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