4 Replies Latest reply: Nov 1, 2011 5:57 PM by 896854 RSS

    Can't get message/delivery-status part content from Message

    896854
      I'm trying to read a DSN message from a mailbox (with IMAP).

      Although I can get the "text/plain" and the original message part, I get a "java.io.IOException: No content" when trying to get the "message/delivery-status" part.

      When I check the email source code, I can see that there are contents in the "message/delivery-status" part.

      Trying to create a DeliveryStatus object using the MimeBodyPart input stream also throws the following execption:

      javax.mail.MessagingException: Error in input stream;
      nested exception is:
           java.io.IOException: No content

      Is there a way to get the "delivery-status" part content and parse it or creat a DeliveryStatus object from it?

      Message looks like this:

      MIME-Version: 1.0
      Content-Type: multipart/report;boundary="_===2030706====smtp.mailserver.com===_";
      report-type="delivery-status"


      --_===2030706====smtp.mailserver.com===_
      Content-Type: text/plain;charset="utf-8"

      Failed to deliver to 'bounedemail@email.com'
      SMTP module(domain email.com) reports:
      email.com: no response


      --_===2030706====smtp.mailserver.com===_
      Content-Type: message/delivery-status

      Reporting-MTA: dns; smtp.mailserver.com

      Original-Recipient: rfc822;<bounedemail@email.com>
      Final-Recipient: rfc822;<bounedemail@email.com>
      Action: failed
      Status: 4.0.0

      --_===2030706====smtp.mailserver.com===_
      Content-Type: text/rfc822-headers

      Received: from [XXX.XXX.XXX.XXX] (HELO smtp.mailserver.com)
      by smtp.mailserver.com (CommuniGate Pro SMTP 5.3.13 community)
      with ESMTPS id 1982792 for bounedemail@email.com; Wed, 26 Oct 2011 06:17:37 -0400
      Date: Wed, 26 Oct 2011 06:17:25 -0400 (EDT)
      From: "me@gmail.Com" <me@gmail.com>
      To: bounedemail@email.com
      Message-ID: <557901950.374233.1319624256971.JavaMail.info@sun.com>
      Subject: Email Subject!
      MIME-Version: 1.0
      Content-Type: multipart/alternative;
           boundary="----=_Part_374232_2068297477.1319624256967"
      X-FTS-Received-At: Wed Oct 26 06:17:31 EDT 2011

      _===2030706====smtp.mailserver.com===_

      Edited by: 893851 on Oct 30, 2011 5:58 AM
        • 1. Re: Can't get message/delivery-status part content from Message
          Bill Shannon-Oracle
          I can't reproduce the problem using the current version of JavaMail. Which version are you using?

          Try this:

          Save the message to a file "msg.txt".
          Compile the msgshow.java demo program included with JavaMail.
          Run: "java -cp mail.jar:dsn.jar:. msgshow -m < msg.txt", that is, run msgshow against the file, using the -m option, with the mail.jar and dsn.jar files in the classpath.

          If that works, you'll get output like this:

          This is the message envelope
          ---------------------------
          SUBJECT: null
          SendDate: UNKNOWN
          FLAGS:
          X-Mailer NOT available
          CONTENT-TYPE: multipart/report;
               boundary="_===2030706====smtp.mailserver.com===_";
               report-type=delivery-status
          This is a Multipart
          ---------------------------
          CONTENT-TYPE: text/plain; charset=utf-8
          This is plain text
          ---------------------------
          Failed to deliver to 'bounedemail@email.com'
          SMTP module(domain email.com) reports:
          email.com: no response


          CONTENT-TYPE: message/delivery-status
          This is an unknown type
          ---------------------------
          DeliveryStatus: Reporting-MTA=dns; smtp.mailserver.com, #Recipients=1
          CONTENT-TYPE: text/rfc822-headers
          This is an unknown type
          ---------------------------
          com.sun.mail.dsn.MessageHeaders@66e815



          If that works for you, and it still fails using IMAP, post the IMAP protocol trace (see the FAQ),
          or send it to me at javamail_ww@oracle.com.
          • 2. Re: Can't get message/delivery-status part content from Message
            896854
            Here are the version details:
            JavaMail version 1.4.4
            java version "1.6.0_22"

            Reading the mail from a text file works ok for me too. Actually it seems that works fine using POP3 too.

            I tried reading it from IMAP using the msgshow demo program and got the same exception:
            java.io.IOException: Exception creating DeliveryStatus in message/delivery-status DataContentHandler: javax.mail.MessagingException: Error in input stream;
              nested exception is:
                 java.io.IOException: No content
                 at com.sun.mail.dsn.message_deliverystatus.getContent(message_deliverystatus.java:111)
                 at javax.activation.DataSourceDataContentHandler.getContent(DataHandler.java:790)
                 at javax.activation.DataHandler.getContent(DataHandler.java:537)
                 at javax.mail.internet.MimeBodyPart.getContent(MimeBodyPart.java:637)
                 at msgshow.dumpPart(msgshow.java:298)
                 at msgshow.dumpPart(msgshow.java:284)
                 at msgshow.main(msgshow.java:224)
            Here is the IMAP trace:
            DEBUG: JavaMail version 1.4.4
            DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
            DEBUG: Tables of loaded providers
            DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
            DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
            DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
            DEBUG: setDebug: JavaMail version 1.4.4
            DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc]
            DEBUG: mail.imap.fetchsize: 16384
            DEBUG: mail.imap.statuscachetimeout: 1000
            DEBUG: mail.imap.appendbuffersize: -1
            DEBUG: mail.imap.minidletime: 10
            DEBUG: trying to connect to host "imap.mailserver.com", port 143, isSSL false
            * OK IMAP Server 5.3.12 at smtp.mailserver.com ready
            
            A0 CAPABILITY
            
            * CAPABILITY IMAP4 IMAP4REV1 ACL NAMESPACE UIDPLUS IDLE LITERAL+ QUOTA ID MULTIAPPEND LISTEXT CHILDREN BINARY ESEARCH LOGIN-REFERRALS UNSELECT SASL-IR STARTTLS AUTH=LOGIN AUTH=PLAIN AUTH=CRAM-MD5 AUTH=DIGEST-MD5 AUTH=GSSAPI AUTH=MSN AUTH=NTLM
            
            A0 OK completed
            
            DEBUG IMAP: AUTH: LOGIN
            DEBUG IMAP: AUTH: PLAIN
            DEBUG IMAP: AUTH: CRAM-MD5
            DEBUG IMAP: AUTH: DIGEST-MD5
            DEBUG IMAP: AUTH: GSSAPI
            DEBUG IMAP: AUTH: MSN
            DEBUG IMAP: AUTH: NTLM
            DEBUG: protocolConnect login, host=imap.mailserver.com, user=outbound_bounce@mailserver.com, password=<non-null>
            A1 AUTHENTICATE PLAIN
            
            + 
            
            AG91dGJvdW5kX2JvdW5jZUBmb29kdGVjc29sdXRpb25zLmNvbQB1b3dxMzRyNA==
            
            A1 OK completed
            
            A2 CAPABILITY
            
            * CAPABILITY IMAP4 IMAP4REV1 ACL NAMESPACE UIDPLUS IDLE LITERAL+ QUOTA ID MULTIAPPEND LISTEXT CHILDREN BINARY ESEARCH LOGIN-REFERRALS UNSELECT SASL-IR STARTTLS AUTH=LOGIN AUTH=PLAIN AUTH=CRAM-MD5 AUTH=DIGEST-MD5 AUTH=GSSAPI AUTH=MSN AUTH=NTLM
            
            A2 OK completed
            
            DEBUG IMAP: AUTH: LOGIN
            DEBUG IMAP: AUTH: PLAIN
            DEBUG IMAP: AUTH: CRAM-MD5
            DEBUG IMAP: AUTH: DIGEST-MD5
            DEBUG IMAP: AUTH: GSSAPI
            DEBUG IMAP: AUTH: MSN
            DEBUG IMAP: AUTH: NTLM
            DEBUG: connection available -- size: 1
            A3 SELECT inbox
            
            * FLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Hidden $Media $Forwarded Junk $Label1 $Label2 $Label3)
            
            * OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Hidden $Media $Forwarded Junk $Label1 $Label2 $Label3)] limited
            
            * 6223 EXISTS
            
            * 0 RECENT
            
            * OK [UIDNEXT 6224] predicted next UID
            
            * OK [UIDVALIDITY 329631087] UIDs valid
            
            * OK [UNSEEN 3] message 3 is first unseen
            
            A3 OK [READ-WRITE] SELECT completed
            
            Getting message number: 1
            This is the message envelope
            ---------------------------
            A4 FETCH 1 (ENVELOPE INTERNALDATE RFC822.SIZE)
            
            * 1 FETCH (ENVELOPE ("Thu, 13 Oct 2011 14:24:11 -0400" "Undeliverable mail: Email Subject" ((NIL NIL "MAILER-DAEMON" "outbound.mailserver.com")) ((NIL NIL "MAILER-DAEMON" "outbound.mailserver.com")) ((NIL NIL "MAILER-DAEMON" "outbound.mailserver.com")) ((NIL NIL "user" "yahoo.com")) NIL NIL NIL "<receipt-1887834@outbound.mailserver.com>") INTERNALDATE "13-Oct-2011 18:24:19 +0000" RFC822.SIZE 3182)
            
            A4 OK completed
            
            FROM: MAILER-DAEMON@outbound.mailserver.com
            REPLY TO: MAILER-DAEMON@outbound.mailserver.com
            TO: user@yahoo.com
            SUBJECT: Undeliverable mail: Email Subject
            SendDate: Thu Oct 13 21:24:11 EEST 2011
            A5 FETCH 1 (FLAGS)
            
            * 1 FETCH (FLAGS (\Seen))
            
            A5 OK completed
            
            FLAGS: \Seen
            A6 FETCH 1 (BODY.PEEK[HEADER.FIELDS (X-Mailer)])
            
            * 1 FETCH (BODY[HEADER.FIELDS ("X-Mailer")] {2}
            
            
            
            )
            
            A6 OK completed
            
            X-Mailer NOT available
            A7 FETCH 1 (BODYSTRUCTURE)
            
            * 1 FETCH (BODYSTRUCTURE (("text" "plain" ("charset" "utf-8") NIL NIL "8bit" 294 5 NIL NIL NIL NIL)("message" "delivery-status" NIL NIL NIL "8bit" 195 NIL NIL NIL NIL)("text" "rfc822-headers" NIL NIL NIL "8bit" 891 18 NIL NIL NIL NIL) "report" ("boundary" "_===1887834====outbound.mailserver.com===_" "report-type" "delivery-status") NIL NIL NIL))
            
            A7 OK completed
            
            CONTENT-TYPE: multipart/report; 
            
                 boundary="_===1887834====outbound.mailserver.com===_"; 
            
                 report-type=delivery-status
            This is a Multipart
            ---------------------------
            CONTENT-TYPE: text/plain; charset=utf-8
            This is plain text
            ---------------------------
            A8 FETCH 1 (BODY[1]<0.294>)
            
            * 1 FETCH (BODY[1]<0> {294}
            
            Failed to deliver to 'user@domain.com'
            
            SMTP module(domain domain.com) reports:
            
             message text rejected by mx1.biz.mail.yahoo.com:
            
             554 delivery error: dd This user doesn't have a domain.com account (user@domain.com) [0] - mta1025.biz.mail.sk1.yahoo.com
            
            
            
            )
            
            A8 OK completed
            
            Failed to deliver to 'user@domain.com'
            
            SMTP module(domain domain.com) reports:
            
             message text rejected by mx1.biz.mail.yahoo.com:
            
             554 delivery error: dd This user doesn't have a domain.com account (user@domain.com) [0] - mta1025.biz.mail.sk1.yahoo.com
            
            
            
            
            CONTENT-TYPE: message/delivery-status
            A9 FETCH 1 (BODY[2]<0.195>)
            
            * 1 FETCH (BODY[2]<0> NIL)
            
            A9 OK completed
            
            DEBUG IMAP: IMAPProtocol noop
            A10 NOOP
            
            A10 OK completed
            
            Oops, got exception! Exception creating DeliveryStatus in message/delivery-status DataContentHandler: javax.mail.MessagingException: Error in input stream;
              nested exception is:
                 java.io.IOException: No content
            • 3. Re: Can't get message/delivery-status part content from Message
              Bill Shannon-Oracle
              As I suspected, it's a bug in your mail server. Please report it to the vendor.

              Here's the bug:

              A9 FETCH 1 (BODY[2]<0.195>)
              * 1 FETCH (BODY[2]<0> NIL)

              Instead of responding with the content of that body part, the server returns NIL.

              The JavaMail FAQ shows how to work around bugs such as this in IMAP servers.
              • 4. Re: Can't get message/delivery-status part content from Message
                896854
                Thank you very much for your help.

                Using the workaround mentioned in FAQ allowed to retrieve the delivery-status part using IMAP:
                http://www.oracle.com/technetwork/java/javamail/faq-135477.html#imapserverbug