[Get started with JavaMail] This is the first article about javamail.

Source: Internet
Author: User

[Get started with JavaMail] This is the first article about javamail.

Nowadays, email plays an increasingly important role in our life, and almost everyone of us will deal with it (at least from time to time we will receive inexplicable spam). At work, communication via email can make our work traceable and formal. This is done manually by us, after an account is registered on a website, the website will automatically send a welcome email and ask us to confirm whether it is registered to prevent malicious registration. Of course, this cannot be performed manually as we do at work. JavaMail in the 13 core technologies of Java provides us with APIs to perform relevant operations on emails.

I. email server

To provide email on the Internet, you must have a dedicated email server. A large number of email servers are set up on the Internet, such as sina.com, qq.com, and 163.com, many companies also provide email servers for internal employees, which can send and receive emails between each other. What is the role of the email server? It can help us send emails, receive emails, and provide us with email retrieval services, this is similar to the Post Office in real life. It can receive emails, provide services for us to retrieve emails, and send emails to us. The image below illustrates the functions of the mail server.

(1) receive user-delivered mails;
(2) Forward the emails delivered by users to the target email server;
(3) receive emails forwarded by other email servers and store the emails in their managed user mailboxes;
(4) provides reading services for users who come to read emails.

The mail server can be divided into two types by communication protocol: SMTP server and POP3/IMAP server. The functions of 1, 2, and 3 are completed by the SMTP server, the 4 function is implemented by the POP3 server.

Ii. Email

Each email server can have multiple email addresses, which are also called e-mail addresses. They are similar to mailing addresses in real life, you can use this address to receive and send emails from others. To obtain an email address, you must apply on the email server. Specifically, an email address is actually an account applied for on the email server. The mail server saves the received emails to the mailbox space allocated to an account (so we need to regularly clean up our emails, otherwise, a new email cannot be received when the allocated space is exceeded. you can log on to the email server using the user name and password you have applied for to check the email you have received from this address.
Iii. Email transmission process

The email transmission process can be used to indicate

Process description:

1. The mail client of the lisi@sina.com establishes a network connection with the SMTP server of sina, and logs on with the username and password of lisi, and sends the mail to the SMTP server of sina using the SMTP protocol;

2. After receiving the address mail submitted by the lisi@sina.com, the sina SMTP server first follows the recipient's address suffix to determine whether the street address belongs to the jurisdiction of the SMTP server, if yes, the mail is directly stored in the recipient's mailbox. Otherwise, the sina SMTP server queries the DNS server for the MX record of the domain name indicated by the recipient's email address suffix (sohu.com, to obtain the SMTP server information of sohu, establish a connection with the SMTP server of soho, and send the mail to the SMTP server of sohu using the SMTP protocol;

3. After receiving an email from the sina SMTP server, the SMTP server of soho determines whether the email belongs to the SMTP server based on the recipient's address, if yes, the mail will be directly stored in the recipient's mailbox; otherwise, the sohu SMTP server may continue to forward the mail;

4. The wangwu@sohu.com account establishes a network connection with the soho POP3/IMAP server through the client, and after successfully logging on, then through the POP3/IMAP protocol to check whether there is a new mail in the wangwu@sohu.com mailbox, if there is, the POP3 or IMAP protocol is used to read emails in the mailbox.

Most of the above content is excerpted from Java mail development details.

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.