Working with Documents
After downloading the JavaMail API, the documents contained therein are very useful and the documents are stored in the subdirectory/docs/javadocs/of the directory where the JavaMail resides. The following describes some of the components that are required in the messaging tool. Please refer to the JavaMail documentation for more information.
Components needed to send email using javamail
JavaMail's structural system makes it easy to deal with emails. Here are some of the classes we need.
Properties: JavaMail requires properties to be used when creating a Session object. The object will look for a property string named "Mail.smtp.host", whose property value is the host that sent mail.
Properties Props = new properties ();
Props.put ("Mail.smtp.host", "smtp.jspinsider.com");
Session dialog: The Sessions object represents a mail conversation in JavaMail. Each JavaMail based tool requires at least one session, but can have multiple sessions. In this case, the session object needs to know the SMTP server that handles the message. This can be done by creating a Session object:
Session sendmailsession;
Sendmailsession = session.getinstance (props, null);
Transport (transmission): The message is either sent out or received. The JavaMail represents these two actions in two different objects, namely transport and store. The transport object is used to send information, and the store is used to receive information. In this tutorial, we need to use the transport object.
Transport transport;
Transport = Sendmailsession.gettransport ("SMTP");
You can use the Gettransport method of the JavaMail session object to initialize the transport object. The string parameter passed defines the protocol used in the return object. Here, we can see that using JavaMail saves a lot of time, otherwise we have to do our own programming to complete the entire implementation of SMTP, and JavaMail has done the work in advance.
Note: JavaMail is not supported by anything, and currently supports only IMAP,SMTP and POP3. In addition, if you need to support other protocols, you will need to wait for the next version of JavaMail, or you can construct the agreement yourself.
Message: The Messages object represents the actual email message to send. The message object created is MimeMessage, and the object needs to know which javamail session to select.
Message Newmessage = new MimeMessage (sendmailsession);
That's it, all we need is the four objects described above. Next, you'll see how to put these objects in your JSP.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.