Introduction to JavaMail Common classes

Source: Internet
Author: User

Reprinted from: http://blog.csdn.net/silence1214/article/details/3461213

(a) Javax.mail.Session:

The session class represents a single mail session in JavaMail. Each JavaMail-based application has at least one session and can produce multiple sessions. You should usually establish a mail session before sending a message. Here are some common ways to create a message painting.

Session session = Session.getinstance (properites props, Authenticator a);

(ii) Javax.mail.Transport

Messages can be sent or received. JavaMail use transport to complete the sending of the message. Transport contains a static Send method. The message is sent by using the following method;

Transport.send (MimeMessage msg); (iii) Javax.mail.MimeMessage The object is information that is actually sent by e-mail messages. Mail objects are typically created with mimemessage, You should pass in a message session parameter when you create the object. This class uses the InternetHeaders class to parse and save the top-level RFC 822 file headers for e-mail. The class contains the following properties

Protected byte[] Content byte array of the e-mail contents

Protected InternetHeaders Headers Returns the object that holds the e-mail file header

void Addfrom (address[] addresses set the sender's address for the e-mail

void AddHeader (string name, string value) adds value to the file header of name;

void Addrecipients (Message.recipienttype type, address[] addresses) This method also has an overloaded method that increases the pickup address for the specified type.

Address[] Getfrom Returns the address list of the sender of this e-mail

void SetContent (Multipart MP) set content for this e-mail

Here's how to create message information

Message msg = new MimeMessage (Session sendmailsession);

(iv) Javax.mail.Address the object is used to determine the sender/recipient address. Like a message, address is an abstract class, and time uses his subclasses. Javax.mail.internetAddress class. You can create the address of the sender/recipient in the following ways:

InternetAddress from = new InternetAddress (String address);

(v) Java.mail.Store Read, write, monitor, find, etc. on the actual specific e-mail protocol, and access the Javax.mail.Folder class through the Javax.mail.Store class. You can create a Store instance in the following ways

Store store = GetStore (String protocol);

Store.connect (popserver,username, password)

(vi) Javax.mail.Multipart The class is a container for storing e-mail content, and it defines methods for adding and deleting e-mail content that is received. Mutipart is an abstract class that typically uses the screwdriver class Javax.mail.Internet.MimeMutipart class to complete the MimeMessage object. You can create a Mimemutipart object by using the following method

Mimemutipart multipart =new mimemultipart ();

Introduction to JavaMail Common classes

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.