2 Replies Latest reply on Feb 9, 2013 10:33 PM by Hamit Hasanhocaoglu

    Requesting different DSN per recipient

    Hamit Hasanhocaoglu
      Hello everyone;

      I know that it is possible to request DSN using SMTPMessage.setNotifyOptions(int options) but this applies to all recipients as SMTPTransport.rcptTo() method is:
      if (supportsExtension("DSN")) {
               if (message instanceof SMTPMessage)
                notify = ((SMTPMessage)message).getDSNNotify();
               if (notify == null)
                notify = session.getProperty("mail." + name + ".dsn.notify");
               // XXX - check for legal syntax?
               if (notify != null)
                dsn = true;
           // try the addresses one at a time
           for (int i = 0; i < addresses.length; i++) {
               sfex = null;
               InternetAddress ia = (InternetAddress)addresses;
           String cmd = "RCPT TO:" + normalizeAddress(ia.getAddress());
           if (dsn)
                cmd += " NOTIFY=" + notify;
           // send the addresses to the SMTP server

      which writes same NOTIFY option for all RCPT TO: commands. I have a requirement to request different DSN for each recipient and RFC1891 (which is linked by SMTPMessage javadoc also) allows that:
      MAIL FROM:<Alice@Pure-Heart.ORG> RET=HDRS ENVID=QQ314159
      250 <Alice@Pure-Heart.ORG> sender ok
      RCPT TO:<Bob@Big-Bucks.COM> NOTIFY=SUCCESS \
      250 <Bob@Big-Bucks.COM> recipient ok
      RCPT TO:<Carol@Ivory.EDU> NOTIFY=FAILURE \
      My question is, (assuming RFC1891 is not fully implemented by Java Mail API), is it possible that per recipient DSN feature will be implemented in near future? If not, extending both SMTPMessage (override addRecipients method to accept notify option along with the recipient address) and SMTPTransport (to override rcptTo method to write notify option associated with each recipient) would be the correct way to achieve this ?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
        • 1. Re: Requesting different DSN per recipient
          Bill Shannon-Oracle
          There are no immediate plans to add this, but feel free to file an enhancement request
          in the issue tracker for the JavaMail project: http://kenai.com/projects/javamail.

          A workaround would be to send the message multiple times, to one recipient at a time,
          and configure the DSN options for that one recipient. The message content can be the
          same for all recipients, and can include all recipients in the message headers, and
          you can pass in the single recipient using the sendMessage method. That's probably
          fine if there are only a few recipients for the message.

          The obvious way to implement this feature is to create a subclass of InternetAddress
          that allows you to specify this information per-recipient. Unfortunately, when you add
          those recipients to the message, that information will be lost, since the recipients are
          turned into strings and added to the corresponding header. Possibly SMTPMessage
          could keep track of the InternetAddress objects as well so that SMTPTransport can
          access them later and get the per-recipient DSN information.
          • 2. Re: Requesting different DSN per recipient
            Hamit Hasanhocaoglu

            Thank you Bill. I created an enhancement request on SMTP component: http://kenai.com/bugzilla/show_bug.cgi?id=5821

            Edited by: Hamit Hasanhocaoglu on 09.┼×ub.2013 14:33