tags:

views:

339

answers:

1

I want a delivery receipt after sending email through java mail service and also want to save this receipt to CSV file in text format, send me a running code.

+1  A: 

In order to request a delivery receipt you upon delivery you have to use com.sun.mail.smtp.SMTPMessage. Given your message in msg:

SMTPMessage smtpMsg = new SMTPMessage(msg);
smtpMsg.setReturnOption(SMTPMessage.RETURN_HDRS);
smtpMsg.setNotifyOptions(
  SMTPMessage.NOTIFY_DELAY|SMTPMessage.NOTIFY_FAILURE|SMTPMessage.NOTIFY_SUCCESS);

Now you will receive a delivery-status mail upon delivery. This mail is of mime-type multipart/report, sub-tpye delivery-status. It consists of text/plain part with a human readable message, a message/delivery-status part with a machine readable (and standardized) message as wells as an (optional) part with the original message attached. Think about what exactly you want to save to file.

See also RFC 1891 - 1894 for reference.

erik