Spring 邮件 MimeMessage 有一个不正确的“From”放
我正在使用 spring mail 通过 google 的 smptp 服务器发送电子邮件。我将电子邮件模板设置为“发件人”标头,但由于某种原因,当我作为发件人收到邮件时,我得到了 smtp 帐户的所有者。 (碰巧又是我)。
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setText(forgottenPassowrdMailTemplate.getText()
.replace("%firstName%", token.getUser().getFirstName())
.replace("%lastName%", token.getUser().getLastName())
.replace("%link%", url + token.getToken()), true);
helper.setTo(token.getUser().getEmail());
helper.setFrom(forgottenPassowrdMailTemplate.getFrom());
helper.setSubject(forgottenPassowrdMailTemplate.getSubject());
我是不是忘记了什么?我明确设置“From”标头
I am using spring mail to send an email via google's smptp server. I am setting my email templates "From" header but for some reason when I do receive the mail as a sender I get the owner of the smtp account. (which happens to be me again).
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setText(forgottenPassowrdMailTemplate.getText()
.replace("%firstName%", token.getUser().getFirstName())
.replace("%lastName%", token.getUser().getLastName())
.replace("%link%", url + token.getToken()), true);
helper.setTo(token.getUser().getEmail());
helper.setFrom(forgottenPassowrdMailTemplate.getFrom());
helper.setSubject(forgottenPassowrdMailTemplate.getSubject());
am I forgetting something ? I a am explicitly setting the "From" header
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您设置的
发件人
地址与帐户地址不同。 Google 采取了安全措施来避免滥用,如果您可以通过 Google 的 SMTP 服务器使用任意发件人
地址发送邮件,这可能是致命的。您需要将您的其他帐户与您要用来发送邮件的帐户关联并验证。请参阅此处。您的原始电子邮件地址仍将显示在标题中并且对收件人可见。但为什么不直接使用其他帐户凭据(以及邮件服务器,如果它不是 Google 帐户)呢?
You are setting a
from
address that is different from the account's address. There are security measures by Google to avoid abuse, which could be fatal if you could just send with any arbitraryfrom
address via Google's SMTP server. You need to link and verify your other account with the account you want to send the mail with. See here. Your original email address will still be available in the headers and visible to the receipient.But why don't you just use the other accounts credentials (and mail server, if it is not a Google account)?