SMW SMW - 1 month ago 17
Java Question

How to redirect email from invalid email address to some other email address in Java

I have method for sending emails:

public static void sendMail(InternetAddress[] to, InternetAddress[] cc, InternetAddress[] bcc, String subject, String body, String priority, String type) throws MessagingException {
String host = "";

Properties properties = System.getProperties();
properties.setProperty("", host);

Session session = Session.getInstance(properties);

MimeMessage msg = new MimeMessage(session);
msg.addHeader("X-Priority", priority);
msg.addRecipients(Message.RecipientType.TO, to);

if (cc != null) {
msg.addRecipients(Message.RecipientType.CC, cc);

if (bcc != null) {
msg.addRecipients(Message.RecipientType.BCC, bcc);

if (type == null) {
} else {
msg.setText(body, "utf-8", type);


and I want that, if some user replies to such email, his email will be redirected to some other email (e.g.

Answer Source

Try msg.setReplyTo(replyTo); Please note that replyTo is not same as From Address