0
votes

I have setup mail server mail.example.com at smtp. Trying to send email with that, and the mail server send the mail correctly.

But if the email bounces, I want them to read at another email address, thats one gmail address. So for that i have tried doing this

SMTPMessage sMTPMessage = new SMTPMessage(mailSession);

sMTPMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
sMTPMessage.setFrom(new InternetAddress(from));
sMTPMessage.setSubject(subject);
sMTPMessage.setContent(body, contentType);
sMTPMessage.setEnvelopeFrom(bounceAddr);


SMTPTransport smtpTrans = new SMTPTransport(mailSession, new URLName("smtp", smtpServer, port, null, userid, password));

smtpTrans.connect();
smtpTrans.sendMessage(sMTPMessage, sMTPMessage.getAllRecipients());
System.out.println("transport "+smtpTrans.getReportSuccess());
smtpTrans.close();

But it didn't worked. and so I am not getting the bounce email information. Also I tried by setting mail.smtp.from property that also didn't worked.

Also I saw this

props.put("smtp.mail.from", bounceAddr);

But the from email address is not at the mail server, its on my gmail address. So is there any issue with from address domain ?

1

1 Answers

0
votes

If you're using properties, make sure you don't have a typo in the property name, as you do above.

You can make sure that JavaMail is using the envelope From address that you specify by turning on JavaMail session debugging and looking for the MAIL command in the SMTP protocol in the debug output.

But the real problem is likely one of:

  1. Not all mail servers honor this information, even though they should.
  2. One of the mail servers starting with your mail server and through to the destination mail server may not have forwarded this information as it forwarded your message, thus leaving the mail server that detects the problem without the information to return the error message to the proper place.
  3. Your mail server may not be honoring this information because it's not an email address in the domain managed by your mail server.

Some of these problems may be fixable by checking the configuration and behavior of your mail server. But in the end you simply can't rely on always getting an error message back when you send to an invalid address.

You can find more information in the JavaMail FAQ.