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 ?