Use javamail to receive hotmail bounce messages

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, seeRFC1892, Sun ChineseJavamail FaqThere are also related descriptions, I extract as follows:

Q.When a message cannot be transmitted, a failure message is returned. How can I detect these "Bounce" messages?
A:Although there is an Internet standard for reporting such errors (for the multipart/report MIME type, seeRFC1892), But it has not been widely implemented yet.RFC1211I have 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 technology is Variable Envelope Return Paths,
Http://cr.yp.to/proto/verp.txtDescribes this technology.

I modified the program and simply processed it. 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 ")){
// 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, seeAccessing Hotmail via JavaMail.


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.