使用javamail进行邮件转发

时间:2014-05-25 10:20:40

标签: email javamail email-integration

关注this帖子,我正在尝试使用javamail实现邮件转发到gmail, 但是我没有设法让电子邮件包含来自和来自cc行的原始电子邮件。 无论我做什么,电子邮件都会显示为会话验证的用户发送的电子邮件。 简化请求:如何重新定义发送到Gmail的电子邮件的FROM,TO,CC和BCC行,而不会真正向此地址发送电子邮件。

类似的东西:

@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 个答案:

答案 0 :(得分:-1)

一般情况下,Gmail不允许您从任何发件人地址发送电子邮件。有关详细信息,请参阅this Gmail help page

相关问题