Javamail receives a hotmail Bounce Message

Source: Internet
Author: User

Hotmail is my most commonly used email client. Although the size of Hotmail is a little small nowadays, the speed is often slow, so people can not help but greet Gates mother. However, it is undeniable that it is quite rich and stable. In particular, its page design is an important reference for web programmers.

Unlike many POP3 servers, Hotmail provides message transmission status notifications (multipart/REPORT ). I previously wrote that the mail client only supports receiving multipart/related, multipart/alternative, multipart/mixed, and other multimedia types of mail. Others are ignored because they are not common.

If the customer does not agree, what else can be said? What is more important than making the customer satisfied? Before the bill is paid.

For details about multipart/report mail types, see rfc1892. Sun's Chinese javamail FAQ also provides relevant instructions. The following is an excerpt:

Q. When a message cannot be sent, a failure message is returned. How can I detect these "Bounce" messages?

A: Although there is an internet standard used to report such errors (for the multipart/report MIME type, see rfc1892), it has not been widely implemented yet. Rfc1211 discussed this issue in depth, including a large number of examples.

In Internet email, whether a specific mailbox or user name exists can only be determined by the final server that sends the message. Messages may pass through several relay servers (they cannot detect errors) and then reach the final server. Generally, when the server detects this error, it returns a message to the sender of the original message, indicating the cause of the failure. Many Internet standards have discussed delivery status notifications, but many servers do not support these new standards. Instead, they use special techniques to return such error messages. This makes it very difficult to associate the "rebound" message with the original message that generates the problem (note that this problem is completely irrelevant to javamail ).

There are a lot of techniques and testing methods to deal with this problem, but they are not perfect. One technique is variable envelope return paths, which is described by the http://cr.yp.to/proto/verp.txt.

I modifiedProgram, But also made some simple processing,CodeAs follows:

Private void parsemultipart (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 ")){
// Process text content
}
/******* Process attachments, images, and so on ********/
} Else if (part. ismimetype ("message/delivery-status ")){
Part. setfilename ("details.txt"); // The content of details.txt, which is the mail header information of the Status notification.
Saveattachedfile (part );
} Else if (part. ismimetype ("message/rfc822 ")){
Mimebodypart MBP = new mimebodypart (part. getinputstream ());
Part. setfilename (MBP. getheader ("subject", null) + ". eml"); // use the return title as the file name in the format of outlook.
Saveattachedfile (part );
}
}
}

To be more friendly, you can also make many improvements, such as finding the original in the sent folder Based on the bounce message, or initiating a notification event. Customers don't need it. I still don't have to be passionate about it.

As we all know, Hotmail uses the WebDAV protocol instead of the POP3 protocol. Use Java to send and receive Hotmail emails. For more information, see accessing Hotmail through javamail.

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.