JavaMail to receive Hotmail's Retreat _jsp programming

Source: Internet
Author: User
Hotmail is my most common email Client. Although the current capacity of Hotmail is small, the speed is often slow to let people can not help but greet gates mother. But it is undeniable that it is very rich, and relatively stable. In particular, its page design is the important reference for me and other web programmers.

Unlike many POP3 servers, Hotmail implements a mail delivery status notification (Multipart/report). I used to write mail clients that only support the collection of multipart/related, Multipart/alternative and multipart/mixed and other multimedia types of mail, others because it is not common, I have ignored.

Customers do not agree, that there is nothing to say, there is nothing more important than to let the customer satisfaction, before the bill.

Introduction to the Multipart/report message type is available in the Rfc1892,sun Chinese Javamail Faq, which I'll extract as follows:

Ask. When a message cannot be delivered, a failure message is returned. How do I detect these "bounce" messages?

A: Although there is an Internet standard for reporting such errors (Multipart/report MIME types, see RFC1892), it is not widely implemented. RFC1211 discussed the issue in depth, including a large number of examples.

In Internet e-mail, a specific mailbox or user name exists and can only be determined by the final server that transmits the message. Messages can pass through several relay servers (they cannot detect errors) before reaching the final server. Typically, when the end server detects this error, it returns a message to the sender of the original message, indicating the cause of the failure. There are many Internet standards that discuss this delivery status notification (Delivery status notifications), but a large number of servers do not support these new standards, but instead use special techniques to return such error messages. This makes it very difficult to correlate the "bounce" message with the original message that caused the problem (note that this problem is completely unrelated to JavaMail).

There are many techniques and heuristics for dealing with this problem, but none of them are perfect. One technique is Variable Envelope return paths,http://cr.yp.to/proto/verp.txt describes this technique.

I modified the program, and I just did some simple processing, the code is as follows:

private void Parsemultipart (Multipart Multipart) throws Exception {
for (int i = 0, n = multipart.getcount (); i < n; i++) {
BodyPart part = Multipart.getbodypart (i);
String disposition = part.getdisposition ();

if (Part.ismimetype ("multipart/*")) {
This.parsemultipart ((Multipart) part.getcontent ());
else if (Part.ismimetype ("text/html")) {
Working with text content
}
/******* processing accessories, pictures, etc. ********/
else if (Part.ismimetype ("Message/delivery-status")) {
Part.setfilename ("Details.txt"); Follow the Outlook,details.txt content, which is the message header information for sending status notifications
Saveattachedfile (part);
else if (Part.ismimetype ("message/rfc822")) {
MimeBodyPart MBP = new MimeBodyPart (Part.getinputstream ());
Part.setfilename (Mbp.getheader ("Subject", NULL) + ". eml"); Follow outlook and use the title of the fallback to do the file name
Saveattachedfile (part);
}
}
}


If you want to be more friendly, you can make a lot of improvements, such as finding the originals in the Sent folder from the letter of withdrawal, or firing a notification event, and so on. Customers do not need, I still do not romantic.

As we all know, Hotmail is not using the POP3 protocol to receive letters, but with WebDAV protocol. Use Java to send and receive Hotmail mail, see "Through JavaMail visit Hotmail mailbox".

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.