Display the contents of a composite message with JavaMail (1)

Source: Internet
Author: User
Tags format mail return
Display Compound message: Contains both pictures and body text, which is usually displayed in HTML format. Simple to understand, is a very beautiful kind of mail.
(Personal note, not very comprehensive)

When we need to do a mail-receiving program, how do we display the contents of a composite message? (See the "Expert outpatient" for the original question)
Today I have a little experience to write out, I hope that the latter can be less detours.
Of course, I hope comrades will correct me.

First, we need to get a message object from the folder. This step is not difficult to achieve. You can see many examples. When we get the message object, the next step is to show his content. Before starting this section, you first need to briefly describe several important types of mimetype:
Text/html
Texl/plain
Multipart/alternative
multipart/related

The first two do not have to introduce, one is HTML format body, one is unformatted body. If your message object is one of those two mimetype. Then your mail is not multipart mail. You can just go and show them. As follows:
Object o = m.getcontent ();
if (M.ismimetype ("Text/plain") | | M.ismimetype ("text/html"))
{
S= "
"+ (String) o+"
";
return s;
}
S is the content string to return. M is the message object.

If your message object is the latter two, it means your email is multipart. Need to do some processing and judgment to normal display content. If the message is multipart, just get the contents of the various parts (part) of the multipart. The content of the entire message is obtained.
if (M.ismimetype ("multipart/*")
{
Multipart MP = (Multipart) o;
int cnt = Mp.getcount ();
for (int i = 0; i < cnt; i++)
{
w=w+ "
"+getpart" (Mp.getbodypart (i), I, 2,x);
}
}

Getpart is the way to get part content.

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.