2017-08-28 79 views
0

我有方法用於發送電子郵件:
如何更改電子郵件地址回覆在Java中

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

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

    Session session = Session.getInstance(properties); 

    MimeMessage msg = new MimeMessage(session); 
    msg.setSubject(subject); 
    msg.addHeader("X-Priority", priority); 
    msg.setFrom("[email protected]"); 
    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) { 
     msg.setText(body); 
    } else { 
     msg.setText(body, "utf-8", type); 
    } 

    Transport.send(msg); 
} 

,我想的是,如果一些用戶回覆此類電子郵件,他的電子郵件將被重定向到其他一些電子郵件(例如[email protected])。

+1

這可能有所幫助:https://coderanch.com/t/274415/java/set-Return-Path-email-address#2823152 –

回答

2

嘗試msg.setReplyTo(replyTo);請注意的replyTo不一樣發件人地址

相關問題