Java email Development (II): Use JMail to send an email with illustrated text and attachments (I)

Source: Internet
Author: User

Sometimes we have this requirement: we need an e-mail that looks rich, including text, hyperlinks, images, and so on, instead of a pile of text. Sometimes we also need to add some attachments in the email. Almost all such emails are supported, such as 163, Sina, Sohu, and QQ (as if Sohu does not support locally uploaded images ). However, we do not know what is behind these emails. Let's take a look at the composition of these emails.

I. Overall structure of composite emails


An email consists of the MIMe message header of the entire email and the MIMe Message Body of the entire email.

The MIMe message header contains the message sender, receiver, and other information. We can see that the MIMe message body contains the content (body and attachment) of the mail. Its type is determined by the"Content-TypeField. Common simple types include text/plain (plain text) and text/html (Hyper text ). The body and the attachment have two parts: the message header and the message body.

2. Combination in MIMe

From the mail structure, we can see that each part of each mail contains two parts: the message header and the message body. The message header generally indicates the type of the message body (multipart type). There are three common types in the mail: multipart/Mixed, Multipart/related and multipart/alternative, as shown in:

We can see that if you want to add attachments to an email, you must define multipart/Mixed <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Latency + 7 S/zsSxvtPrs6zOxLG + memory/memory + Memory + CjxoMj7I/aGi08q8/tfp1q + Memory + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140210/20140210082706103.jpg" alt = "\">

We can clearly see the relationship between objects.

Note:

Detailed slides for Java email development are all sourced from Zhang Xiaoxiang

Appendix:

1. JavaMail jar package: http://download.csdn.net/download/zyh5540/6900667

2. References: http://download.csdn.net/download/zyh5540/6907731


Related Article

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.