Javamail Study Notes (2), javamail API introduction and configuration Development Environment

Source: Internet
Author: User
Tags imap types of functions
1. Introduction to javamail API

Javamail API is a set of standard development kits provided by Sun to facilitate Java developers to send and receive emails in applications. It supports common mail protocols, such: SMTP, POP3, IMAP, and mime. When developers use the javamail API to write mail processing software, they do not need to consider the implementation details at the bottom layer of the mail protocol. They only need to call the corresponding API classes in the javamail development kit. The javamail API is encapsulated in a file named mail. Jar. It is the core jar package that must be used to develop the javamail application.

2. Configure the javamail Development Environment

  1. Download the mail. Jar development kit from the Oracle official website. The latest version is 1.4.5. After the download is successful, a javamail%4_5.zip file will be obtained and then decompressed.
  2. Shows the directory structure after decompression:
    • Mail. jar:Is the core development kit necessary to develop the javamail program.
    • Demo subdirectory:Sample program.
    • Lib subdirectory:This directory contains five independent email development packages: SMTP. jar, pop3.jar, IMAP. jar, and mailapi. Jar. These five jar files are classified packages for mail. Jar files. Mailapi. jar encapsulates the API class for creating mail content and calling mail sending and receiving for common developers. The other three jar files encapsulate the service implementation program whose names correspond to the Protocol. The relationship between mailapi. jar and the other three jar files is like JDBC
      The relationship between APIs and the JDBC drivers implemented by each database is the same. When compiling a Java mail program, you only need the mailapi. jar file. However, you must have the underlying service implementation program of the corresponding mail protocol at runtime. If you only need to use the mail sending function in the application, you can only install SMTP. jar and mailapi. jar files. If the application only needs to use the mail receiving function, you can only install pop3.jar or IMAP. jar and mailapi. jar. JAR file.
    • Doc subdirectory:Javamail API documentation
  3. Install javamail
  • Add the mail. jar file to the system environment variable classpath, as shown in:
  • Copy the mail. jar file to the % java_home % \ JRE \ Lib \ ext directory.
You can install javamail in either of the above two ways.Iii. javamail API classification and architecture Javamail APIs can be divided into the following categories based on their functions:
  1. API for creating and parsing mail content
  2. Email sending API
  3. Email receiving API
The above three types of functions are composed of multiple API classes, but each function has not many core APIs. Other API classes are the auxiliary classes of these core APIs, by understanding the functions and functions of these core APIs, understanding the working relationships and calling processes between them, you can easily compile the javamail program and use helper classes for core APIs, when using these core APIs, you can check the document and understand the usage of these helper classes. As I understand, the core AIP class in javamail contains message, session, transport, and store4 classes. The working relationships between them are shown in: Core API introduction:
  • Message class
The javax. Mail. Message class is the core API for creating and parsing emails. Its instance object represents an email. When sending an email, the client program first uses the mail creation API to encapsulate the data of the email to the message object, and then sends the object to the mail sending API. When the client program receives the mail, the mail receiving API encapsulates the received mail data in the message class instance object, and the client program then uses the mail parsing API, parse the received email data from this object.
  • Session
Javax. mail. the session class is used to define the environment information required by the entire application and collect the session information for establishing a network connection between the client and the mail server, for example, the host name and port number of the email server, and the mail sending and receiving protocols used. The Session Object constructs the store and transport objects for sending and receiving emails Based on the session information, and provides information support for creating message objects for the client.
  • Transport class
The javax. Mail. Transport class is the core API class for sending mails. Its instance object represents the mail sending object that implements a certain mail sending protocol, such as the SMTP protocol. After the client program creates a message object, it only needs to use the mail sending API to obtain the transport object, then pass the message object to the transport object, and call its sending method, you can send an email to the specified SMTP server.
  • Store class
The javax. Mail. Store class is the core API class for receiving emails. Its instance object represents the recipient of a mail receiving protocol, such as POP3 and IMAP. When receiving emails, the client only needs to use the mail receiving API to obtain the store object, and then call the Receiving Method of the store object to obtain the mail data from the specified POP3 server, and encapsulate the mail data into the message object that represents the mail. 4. Introduction to JAF (JavaBeans activation framework, JavaBeans activation framework) is a dedicated Data Processing framework used to encapsulate data and provide interfaces for applications to access and operate data. The javamail API can use JAF to read data from a data source and obtain the MIME type of the data, and use the data to generate the message body and Message Type in the mime message. The main function of JAF is to let Java applications know how to view, edit, and print a data source. As you know, in MS Word programs, you can open a embedded Visio image in a Word document. JAF enables Java programs to complete similar technical applications and let applications know what operations the data source supports, which processing module is called for each operation. For data encapsulated by JAF, the application can complete the following functions through the interface provided by JAF:
  1. Access data in the data source
  2. Know the Data Type of the Data Source
  3. Know the operations that can be performed on data
  4. When a user performs an operation on data, the user automatically creates an instance object for the software parts that perform the operation.
For example, if JAF is used to process an image file, the application can use the interface provided by JAF to obtain the input/output stream for operations on the image file, and the MIME type of the image file, JAF provides operation methods for image files (such as viewing, editing, or printing images). When an application calls these operations, JAF calls the corresponding processing module to process the data. You can download the JAF jar package from the Oracle official website. The downloaded jar package is activation. Jar. The latest version is 1.1. Note:Jdk1.6 integrates the JAF framework. If jdk1.6 or later is used, you do not need to download the JAF framework separately.

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.