弹簧邮件MimeMessage有一个不正确的“从”组 [英] Spring mail MimeMessage has an incorrect "From " set
问题描述
我使用弹簧邮件通过谷歌的smptp服务器发送电子邮件。我设置我的电子邮件模板从标题,但由于某些原因,当我收到邮件作为发件人,我得到了smtp帐户的所有者。 (这恰恰就是我了)。
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());
我忘记了什么?我明确地设置了From头
am I forgetting something ? I a am explicitly setting the "From" header
推荐答案
您正在从$ c设置 $ c>地址不同于帐户的地址。 Google有避免滥用的安全措施,如果您可以通过Google的SMTP服务器从
地址发送任意的任何,那么这可能是致命的。您需要使用要发送邮件的帐户链接并验证您的其他帐户。请参见此处。您的原始电子邮件地址仍然可以在标题中显示给收件人。
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 arbitrary from
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.
但是,为什么不使用其他帐户凭据(和邮件服务器,如果它不是Google帐户)?
But why don't you just use the other accounts credentials (and mail server, if it is not a Google account)?
这篇关于弹簧邮件MimeMessage有一个不正确的“从”组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!