JavaMail

xiaoxiao2021-03-06  43

Multipurpose Internet Mail Extensions (MIME) Specification RFC2045 - RFC2049HTTP: //www.faqs.org/rfcs/rfc2045.htmlhttp://www.faqs.org/rfcs/rfc2046.htmlhttp: //www.faqs.org/rfcs /RFC2047.htmlhttp://www.faqs.org/rfcs/rfc2048.htmlhttp://www.faqs.org/rfcs/rfc2049.html

Package (1.2): mail.jar, Activation.jar

Posts: javax.mail.internet.mimeutilitySun.Misc.Base64Decoder # decodebuffer #encode (jdk1.4 / jre / lib / RT.jar)

Java Mail API Core Class · Javax.mail.Session: The session class defines a basic mail session (SESSION), which is the highest level of the Java Mail API. All other classes are effective via this session. The session object obtains information with java.util.properties objects, such as mail servers, usernames, passwords, and other information shared throughout the application. · Javax.mail.MAESSAGE: Once you get the session object, you can continue to create the message you want to send. This is done by the Message class. Because Message is an abstract class, you must use a subclass, in most cases, Javax.mail.Internet.mimeMeMessage. MimeMessage is an email message that can understand the MIME type and head, just as defined in different RFCs. Although the non-ASCII characters in some headers are also coded, the Message header can only be limited to a US-ASCII character. · Javax.mail.address: Once you have created session and message, you can use Address to determine the letters address with address after filling the content. Like Message, Address is also an abstract class. You are using the Javax.mail.Internet.InternetAddress class. · Javax.mail. AUTHENTICATOR: Like the Java.Net class, JavaMail API can also use Authenticator to access protected resources through the username and password. For JavaMail APIs, these resources are email servers. JavaMail Authenticator is in a javax.mail package, and it is different from the class authenticator in Java.net. Both do not share the same authenticator because JavaMail API is used for Java 1.1, which does not have a Java.net category. To use Authenticator, create a subclass of an abstract class and return to the PasswordAuthentication instance from the getPasswordAuthentication () method. Once you have finished, you must register an Authenticator to Session. Then, when you need to authenticate, you will notify Authenticator. You can pop up the window, or you can read the user name and password from the configuration file (although not encrypted is unsafe), return them to the call as the PasswordAuthentication object. · Javax.mail.Transport: The last part of the message is used to use the Transport class. This type of protocol specified language sends a message (usually SMTP). It is an abstract class, and its work is similar to the session. Only call the static send () method, you can use the default version of the class: Transport.send (Message); or readers can also get a specific instance from the session for your own protocol (if not If you need to pass it), send a message, then close the connection. · Javax.mail.Store: Store class implements read, write, monitor, lookup, etc. on a particular email protocol. You can access the Javax.mail.Folder class through the Javax.mail.Store class.

· Javax.mail.Folder: Folder class is used to hierarchical messages and provide the ability to access Email according to Javax.mail.Message format. -------------------------------------------------- ------------------------------

Ref: http://www.chinabyte.com/20020424/1608502.shtml Read: New MimeMessage (Null, New FileInputStream (FileName); Hierarchical Relationship (from above)

Email: MimeMessage

Email content: 1) Text: MimeMessage # setxt: string 2) HTML: MimeMessage # setContent: MimeMultipart

MIMEMULTIPART: MIMEMULTIPART 1 ------ n mimebodypart mimemultipart # getcount is the number of MIMEBODYPART, the number of mail categories (1) accessories (N-1)

MimeBodyPart, BodyPart: Message Content: #setText Text / HTML Accessories: #setDataHandler (new DataHandler (DataSource)); #setFileName MimeMultipart mm = (MimeMultipart) msg.getContent () for (int i = 0, n = mm.getCount ( ); i

}

DataSource: DataHandlerDataSource, URLDataSource, FileDataSource

Appendix: Java Mail API Basic Concept

What is Java Mail API

JavaMail API is an optional package (standard extension) for reading, writing, and email. Similar to Eudora, Pine, and Microsoft Outlook, this package is used to create a Mail User Agent (MUA) type program. The main use of the API is not transmitted, sent, and forwards messages; this function ranges to some applications, such as Sendmail and other mail transport agents (MTA) types. MUA type program allows users to read and write messages, but it relies on MTA processing actual sends. What is SMTP

SMTP (Simple Mail Transfer Protocol), a simple mail transfer protocol, which defines the mechanism for sending an email. In a JavaMail API environment, JavaMail-based programs will communicate with your company or Internet service provider (ISP's) SMTP server. The SMTP server can turn the message to the recipient SMTP server to eventually get the user to be obtained via POP or IMAP. This is not required to be an open relay, although the SMTP server supports authentication, but also ensures its configuration correctly. The implementation of the JavaMail API is not supported like a configuration server to relay messages or add a delete mail account.

What is POP?

POP (Post Office Protocol), the post office protocol. It is currently available to version 3, so people usually call it POP3, RFC 1939 defines this protocol. POP and SMTP are also a mechanism, most people get emails on the Internet. The agreement specifies that each user can only have a mailbox support. This is what it can do, and this has also caused a lot of confusion. When using POP, many of the user familiar with the user is not supported by POP protocol, such as seeing several new mail messages. These properties are built in programs such as Eudora or Microsoft Outlook, they can remember something, such as the last received email, how much is new. So when using the JavaMail API, if the reader wants such information, it can only be calculated by himself.

What is IMAP

IMAP (Internet Message Access Protocol), the Internet Message Access Protocol, is a more advanced protocol for receiving messages, with its definition in RFC 2060. The IMAP version currently used is 4, and people habits will be called IMAP4. This protocol must be supported when you use IMAP. Cannot only use POP programs for IMAP and count it to support all IMAP all performance. Suppose the mail server supports IMAP, JavaMail-based programs can take advantage of this situation - users can have multiple folders on the server, and these folders can be shared by multiple users. Because of this more advanced performance, you may think that all users will use IMAP. This is not the case. Require the server to receive a new message, send it to the user in the user when the user request, and maintain the message in multiple folders of each user. This allows for a set of messages, but each user will be lost when the user's long-term mail clamp is getting bigger. With POP, you can uninstall the message saved on the mail server.

What is MIMEMIME (MULTIPURPOSE Internet mail extensions), which is the multi-purpose Internet mail extension. It is not an email transfer protocol, but a format that is defined for messages, attachments, and other contents of the transfer content. There are many different RFC documents here: RFC 822, RFC 2045, RFC 2046, and RFC 2047. As a JavaMail API, you usually do not have to worry about these formats. In any case, there must be these formats and the program will be used.

转载请注明原文地址:https://www.9cbs.com/read-80686.html

New Post(0)