簡體   English   中英

如何在Java中更改要回復的電子郵件地址

[英]How to change email address to reply to in 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("noreply@mydomain.com");
    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);
}

我希望,如果某些用戶回復此類電子郵件,他的電子郵件將被重定向到其他電子郵件(例如,support @ mydomain.com)。

嘗試msg.setReplyTo(replyTo); 請注意,replyTo與發件人地址不同

通過設置屬性mail.smtp.from或使用SMTPMessage.setEnvelopeFrom方法來設置“來自的信封”地址。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM