Java邮件API-从默认的电子邮件ID到用于身份验证的电子邮件ID

问题描述 投票:0回答:1

我正在使用JavaMail API从我的应用程序发送电子邮件。以下是创建会话的代码片段:

final String username = "<email id of gmail business account>";
final String password = "<password of the gmail business account>";

Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true"); //TLS

Session session = 
   Session.getInstance(
        props,
        new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password);
                }
            });

下面是用于设置“发件人”的代码段:

msg.setFrom(new InternetAddress(adminUserEmailId, adminUserName));

我在应用程序中使用管理员用户的电子邮件ID来设置“发件人”。但是,当电子邮件发送完毕(我向我的gmail ID发送了一封电子邮件)时,名称正确,但是我看到“发件人ID”设置为gmail企业帐户的电子邮件ID(而不是我为“发件人”设置的电子邮件ID) ”)。有人可以谈谈如何解决这个问题吗?

提前感谢一吨。

javamail
1个回答
0
投票

Gmail help page描述了如何使用不同于您用于登录的发件人地址发送电子邮件。

© www.soinside.com 2019 - 2024. All rights reserved.