JSP and JavaMail 2 (commonly used class introduction)

Source: Internet
Author: User
3.JavaMail Common class Introduction
Prior description:
People who have never used javamail may not be able to understand these introductions, but it does not matter, the following articles have specific examples, and then can be inverted back to see the use of these classes.
(1) Javax.mail.Properties class
JavaMail requires properties to create a Session object. It will look for the string "Mail.smtp.host", the property value being the host that sent the message.
Usage:
Properties Props = new properties ();
Props.put ("Mail.smtp.host", "smtp.163.com");//Can be replaced with your SMTP host name.
(2) Javax.mail.Session class
This session class represents a message session in JavaMail. Each JavaMail application has at least one session but can have any number of sessions.
In this example, the session object needs to know the SMTP server that is used to process the message.
Usage:
Session sendmailsession;
Sendmailsession = session.getinstance (props, null);
(3) Javax.mail.Transport class
Messages are either sent or can be received. JavaMail uses two different classes to accomplish these two functions: transport and store. Transport is used to send information, and the store is used to collect letters. For this tutorial we only need to use the transport object.
Usage:
Transport transport;
Transport = Sendmailsession.gettransport ("SMTP");
Initializes the transport with the Gettransport method of the JavaMail session object. A string that passes past declares the protocol to use for the object, such as "SMTP." This will save us a lot of time. Because JavaMail has a lot of protocols implemented in the Territory.
Note: JavaMail does not absolutely support each protocol and currently supports IMAP, SMTP, and POP3.
(4) Javax.mail.MimeMessage class
The Message object stores the e-mail messages we actually send, and the messages object is created as a MimeMessage object and needs to know which JavaMail session should be chosen.
Usage:
Message Newmessage = new MimeMessage (sendmailsession);
(5) Javax.mail.InternetAddress class
Once you have created the session and message and filled it in with messages, you can use address to determine the mailing addresses. As with the message, the address is an abstract class. You are using the Javax.mail.internet.InternetAddress class.
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.