Mail forwarding with javamail

耗尽温柔 提交于 2019-12-23 04:49:12

问题


Following this thread, I am trying to implement mail forwarding to gmail with javamail, however I don't manage to make the email to contain original from and to and cc lines. Whatever I do, the email appear as it was sent by the user authenticated by the session. To simplify the request: how to redefine FROM, TO, CC and BCC lines of the email sent to gmail without really sending an email to this addresses.

Something like that:

@Test
public void test3() throws Exception {
    SMTPMessage msg = new SMTPMessage(session);
    msg.setSubject("Testing");
    msg.setText("Body of the email");
    // TRYING TO REPLACE "FROM" ADDRES BY from_nobody@nowhere.com
    msg.setRecipients(Message.RecipientType.TO, Constants.GMAIL_ADDRESS);
    msg.setFrom("from_nobody@nowhere.com");
    msg.setEnvelopeFrom("from_nobody@nowhere.com");
    msg.setSubmitter("from_nobody@nowhere.com");
    msg.setReplyTo(InternetAddress.parse("from_nobody@nowhere.com"));
    // BUT IT DOESN"T HELP. 
    // THE USER AUTHENTICATED IN THE SESSION 
    // APPEARS AS THE SENDER OF THE EMAIL IN GMAIL INTERFACE 
    Transport.send(msg);
}

回答1:


In general, Gmail won't let you send email from any From address you want. See this Gmail help page for details.



来源:https://stackoverflow.com/questions/23854259/mail-forwarding-with-javamail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!