I am trying to read the Status header of a bounced email. This site explains better what I am trying...
The original email is composed by several MultiParts objects, so I am reading it in java code:
private void test(MimeMessage message) throws IOException, MessagingException {
if (message.getContent() != null && message.getContent() instanceof Multipart) {
Multipart content = (Multipart) message.getContent();
for (int i = 0; i < content.getCount(); i++) {
BodyPart bodyPart = content.getBodyPart(i);
Enumeration headers = bodyPart.getAllHeaders();
while(headers.hasMoreElements()){
Header header = (Header) headers.nextElement();
LOGGER.info("Header: " + header.getName() + " value: " + header.getValue());
}
}
}
}
The email part I am analyzing:
Content-Description: Delivery report Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit
Reporting-MTA: dns; someLink.com X-Postfix-Queue-ID: EC862F00D0 X-Postfix-Sender: rfc822; receiver@email.com Arrival-Date: Wed, 7 Aug 2013 13:52:43 +0200 (CEST)
Final-Recipient: rfc822; noexisting@email.com Original-Recipient: rfc822;noexisting@email.com Action: failed Status: 5.1.1 Remote-MTA: dns; [somelink.com Diagnostic-Code: smtp; 550-5.1.1 The email account that you tried to reach does not exist. Please try 550-5.1.1 double-checking the recipient's email address for typos or 550-5.1.1 unnecessary spaces.
In my log file I can see only the 3 first headers:
> Header: Content-Description value: Delivery report
> Header: Content-Type value: text/plain; charset=us-ascii INFO
> Header: Content-Transfer-Encoding value: 7bit
Does anyone know why? How could I get the status header? Thanks
I couldn´t find the Status information in the header, and I will take it from the content. It is not an elegant solution, but at least it works. If someone finds a better one, please let me know!
Java code:
StringWriter writer = new StringWriter();
IOUtils.copy(bodyPart.getInputStream(), writer);
LOGGER.info("Content inputstream: " + writer.toString());
Logs:
Content inputstream: Reporting-MTA: dns; srvvie-mx3.styria-multi-media.com X-Postfix-Queue-ID: 2A1A8F00CF X-Postfix-Sender: rfc822; Arrival-Date: Fri, 9 Aug 2013 11:14:02 +0200 (CEST)
Final-Recipient: rfc822; MAILER-DAEMON@domain.com Original-Recipient: rfc822;MAILER-DAEMON@domain.com Action: failed Status: 5.1.1 Remote-MTA: dns; Diagnostic-Code: smtp; 550 5.1.1 Mailbox does not exist