In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use JavaMail in JSP, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
What is JavaMail?
JavaMail is an API released by Sun to handle email. It can easily perform some commonly used mail transfers.
Although JavaMail is one of Sun's API, it has not yet been added to the standard java development kit (Java Development Kit), which means you have to download additional JavaMail files before using it. In addition, you need to have Sun's JavaBeans Activation Framework (JAF). The operation of JavaBeans Activation Framework is very complex, and to put it simply here, the operation of JavaMail must rely on its support. Using these files under Windows 2000 requires you to specify the path to these files, which is similar on other operating systems.
The next part of this guide is the most difficult to understand.
This guide consists of three parts: the HTML table, the combination of JavaMail, JavaMail and JSP.
* part: HTML form
The * * section provides an example of the most basic email sending and receiving program based on HTML. The second part describes the working principle of JavaMail. The third part introduces how to add JavaMail to JSP and create a basic email sending and receiving program.
Partition component
The most important feature of JSP is the ability to divide the entire web page into small components. The components used here include:
● A HTML form used to send information about email to JSP
● A JSP page is used to process and send letters.
The * step is to create a HTML table to send information to the JSP page. You can copy the following HTML code to your computer:
The HTML source code used to send email:
To:
From:
Subject:
Message:
The above program will create a file that contains basic email information (such as pickup address, sending address, topic, and content). Of course, you can decide what information this file contains according to your own needs.
There are two requirements for the use of this HTML file: the * point is that the generated file must be sent to the program that will be introduced later. In this case, it is sendmail.JSP, but when you use it, you must replace it with the URL of the file in the system; the second point is that there must be space to allow the user to send email.
The second part will analyze the characteristics of JavaMail in preparation for the creation of JSP programs in the third part. So next we will learn about JavaMail.
Part two: about JavaMail
The use of documents
The documentation that comes with the downloaded JavaMail API is very useful. You can find it at / docs/javadocs/index.html under JavaMail. The second part mainly analyzes the components of the mail program. You can get more information about this by reading the documentation.
Component to send mail requires the use of JavaMail, which makes it easy to manipulate messages.
Attribute object
JavaMail needs to create a file in the format "mail.smtp.host" to send messages.
Properties props = new Properties (); props.put ("mail.smtp.host", "smtp.JSPinsider.com"); conversation object
All JavaMail-based programs need at least one or all conversation goals.
Session sendMailSession; sendMailSession = Session.getInstance (props, null)
Transmission
The delivery of a message can only be sent or received. JavaMail describes these two different states as transmission and storage. The transfer will send the message, while the store will receive the message.
Transport transport; transport = sendMailSession.getTransport ("smtp")
Using JavaMail can save us a lot of time. JavaMail can take the place of all SMTP.
Note: JavaMail does not fully support all email delivery and collection work. It currently only supports IMAP, SMTP and POP3, but you have to wait for a new version of JavaMail or your own development protocol.
Information object
The message object will truly reflect the email you send.
Message newMessage = new MimeMessage (sendMailSession)
These are all four objects we need. The next step will be how to add objects to the JSP.
Part III: the combination of JavaMail and JSP
Create JSP
Next we will begin to bring them together. The most important thing is to make sure that you classify according to the instructions on the page. Also remember to mark java.util.date on your email.
Second, create a confirmation message to be sent by mail. Confirmation messages can be arbitrary, and it is common to use "your email has been sent (Your mail has been sent)."
How information is created and sent
We have discussed the creation of information objects in the second part. We will manipulate the information below. This is as simple as setting the properties of the information object. You can do this through the following program.
NewMessage.setFrom (new InternetAddress (request.getParameter ("from"); newMessage.setRecipient (Message.RecipientType.TO, new InternetAddress (request.getParameter ("to"); newMessage.setSubject (request.getParameter ("subject")); newMessage.setSentDate (new Date ()); newMessage.setText (request.getParameter ("text"))
You will now start sending messages. It is very simple to implement it through JavaMail.
Transport.send (newMessage)
Combine all the components together
Now all the components are complete. Now put them all in JSP. Pay attention to each error message and feed it back to the user. The code is as follows, which you can use directly by copying them:
Sample JSP email Utility Using JavaMail JSP meets JavaMail, what a sweet combo.
Your mail has been sent.
Thank you for reading this article carefully. I hope the article "how to use JavaMail in JSP" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.