Я не могу перенаправить отклоненную электронную почту на другой адрес электронной почты в Java. Система доставки почты перенаправляет почту самому отправителю. Пожалуйста, найдите код ниже. Я испробовал все предложения, данные Stackoverflow. Но ничего не получается. Заранее спасибо!
public class SendEmail {
public static void main(String[] args) throws Exception {
String from = "fromemail@gmail.com";
String pass ="password";
String to = "wrongemail@gmail.com";
String host = "smtp.gmail.com";
String bounceAddr = "bouncedemail@gmail.com";
Properties properties = System.getProperties();
properties.put("mail.smtp.host", host);
properties.put("mail.smtp.port", "465");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.ssl.trust", host);
properties.put("mail.smtp.ssl.enable", "true");
properties.put("mail.smtp.ssl","true");
properties.put("mail.smtp.from", bounceAddr);
Session session = Session.getDefaultInstance(properties);
session.setDebug(true);
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("This is the Subject Line!");
message.setText("This is actual message");
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {
mex.printStackTrace();
}
}
}