Setting a bounce address in Apache Commons Mail

Using Apache Commons to send email contains the following code.

HtmlEmail email = new HtmlEmail(); email.setHostName(SMTP_HOST_NAME); email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator(SMTP_AUTH_USER, SMTP_AUTH_PWD)); email.setTLS(true); email.setBounceAddress(" aaa@abc.com "); email.setMsg("Hello"); email.setFrom(" bbb@abc.edu "); email.addReplyTo(" bbb@abc.edu "); email.addTo(" i.do.not.exist@abc.gmail.com "); email.send(); 

But the rebound will not work. It sends failures to the party that authenticated the message, which in this example is SMTP_AUTH_USER. So how can I make it bounce correctly?

+4
source share
2 answers

Have you checked with a batch sniffer what really happens? I would not be surprised if the MSA on SMPT_HOST_NAME ignores and redefines your bounce address.

You can try using the SMTP port for the MTA and quickly check whether it matters.

+2
source

To set the bounce address, you can use the setBounceAddress (emailAddressString) method before sending your message.

0
source

All Articles