Spring mail MimeMessage has an incorrect “From ” set

血红的双手。 提交于 2019-12-12 02:28:27

问题


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


回答1:


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.

But why don't you just use the other accounts credentials (and mail server, if it is not a Google account)?



来源:https://stackoverflow.com/questions/9140176/spring-mail-mimemessage-has-an-incorrect-from-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!