如果您指定此项,则邮件将起作用:
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("no-reply@example.com");
如果您通过此类参数指定,则它将不起作用:
spring.mail.properties.mail.smtp.from=no-reply@example.com
spring.mail.from.email=no-reply@example.com
spring.mail.from=no-reply@example.com
如何让它发挥作用?我不想在代码的所有地方都指定相同的message.setFrom("no-reply@example.com");
如果您使用 application.properties,gmail 会抛出此错误:
Our system has detected that this message is 550-5.7.1 not RFC 5322 compliant: 550-5.7.1 'From' header is missing. 550-5.7.1 To reduce the amount of spam sent to Gmail, this message has been 550-5.7.1 blocked.
据了解,您必须自己负责填写该字段
SimpleMailMessage#from。您可以在文档或来源中查看可用设置的列表。如果您想进行自定义设置并在所有必要的地方使用它,请使用Value注释。可以在此处找到使用此注释的示例。