问题
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