Author: Feng
This article describes how to use the Java Web API to implement an e-mail tool. Typically, email tools use the SMTP (Simple Mail Transfer Protocol, Simplicity Mail Transfer Protocol) to send mail and use the POP3 protocol to accept e-mail messages. Only the two protocols are briefly described in this article. If interested readers can refer to the following sites:
Pop3:ftp://ftp.isi.edu/in-notes/rfc1939.txt
Smtp:ftp://ftp.isi.edu/in-notes/rfc2821.txt
Although the JavaMail API is provided in Java, I will not use the JavaMail API in this article because I'll discuss how e-mail software works from the bottom up. The examples in this article were developed under J2SE 1.4.
Format of e-mail
Before you develop your email software, you need to know the format of your email. According to RFC 2882 (http://www.faqs.org/rfcs/rfc2822.html), e-mail is made up of a number of rows, each of which ends with 〈crlf〉 (ASCII code 13 and ASCII code 10). The maximum length of each row is 998 characters. Some of these lines provide the information necessary to send and receive e-mail messages, which are called headers, and all headers form the Header field (header field). Other lines are used to save the details of the message.
The header field provides a lot of information, including the source of the message, the destination of the message, and the subject of the message. Each header is comprised of a name and a colon plus the corresponding value. For example, from:, Send: And reply-to: The source of the message is recorded. The author of the message is recorded in from: The agent that sent the message (either the mail address or the machine name) is specified in sender: reply-to: The e-mail address that accepts the reply is specified in.
A message may have multiple authors, so you can specify one or more mailbox addresses from:. Here are examples from:
From:ray feng〈rayfeng@yahoo.com.cn〉, bogus@yahoo.com.cn
There can be only one sender in an e-mail message. Therefore sender: The value can only contain one mailbox address. If there is only one author in from: and the value of sender: is the same as the value from: Then sender: It will not appear in the e-mail message, otherwise information redundancy will occur, and vice versa sender: Should appear in the message. Here is an example of a sender:
Sender:ray Feng rayfeng@yahoo.com.cn
In an e-mail message, you can specify that a reply be sent to multiple mailbox addresses. So reply-to: can contain one or more mailbox addresses, separated by commas between each address. If there is a reply-to in the message: The reply will be sent to all the addresses listed in reply-to: If there is no reply-to in the message: The reply will be sent to the address listed in from:. So who's going to get the mail? To: and CC: The mailbox address of the accepted message is saved. Both values can contain multiple mailbox addresses.
In addition to the source and recipient of the message, RFC 2882 also defines a number of other headers, such as Subject: Topics that contain e-mail messages. The following is an example of an E-mail header field:
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.