我相信很多人都会问同样的问题,但我找不到一个全面的答案。 我们在悉尼地区部署的EC2实例上运行Web应用程序(myapp.com)。该应用程序通过AWS SES发送电子邮件。由于悉尼没有SES,我们在俄勒冈州配置了SES。我们生成了SMTP凭据并配置了我们的Springboot应用程序以使用这些凭据发送电子邮件。我们能够发送电子邮件并成功发送电子邮件,但它会转到垃圾邮件文件夹。 来自地址的电子邮件是:noreply@myapp.com 我们已在SES控制台中验证了域名 我们已在SES控制台中验证了noreply@myapp.com电子邮件地址 DKIM也已启用并验证
然而, 我们不确定为什么电子邮件会一直传送到SPAM文件夹。 当我查看RAW电子邮件时,我可以看到SPF标题: SPF:NEUTRAL,IP xx.xx.xx.xxx 我没有在我的DNS名称中配置任何SPF记录,但据我所知,我不需要,因为我使用的是SES SMTP服务器,而不是自定义MAIL FROM。
我迷失了为什么电子邮件会被发送到垃圾邮件。 任何人都可以帮忙吗?
答案 0 :(得分:1)
解决了这个问题。 我不确定到底发生了什么,但是当使用SpringBoot JavaMailSenderImpl使用AWS SES发送电子邮件时,所有电子邮件都没有使用DKIM进行签名(传出电子邮件中没有DKIM标头)。这导致一些SMTP服务器将我们的电子邮件视为垃圾邮件。
我已经通过使用Java Mail API(javax.mail)发送电子邮件解决了这个问题,一旦我完成了所有电子邮件消息,所有电子邮件都随DKIM标头一起发送,而不是它们都转到SPAM文件夹(已测试)针对Gmail和Outlook)。
同样,我不确定为什么使用SpringBoot JavaMailSenderImpl导致了这个问题。我的理解是JavaMailSenderImpl在场景后面使用Java Mail,但由于某些原因,没有电子邮件包含DKIM头。
以下是我使用Java Mail的电子邮件发件人,如果它可以帮助那里的任何人。
try {
Properties properties = new Properties();
// get property to indicate if SMTP server needs authentication
boolean authRequired = true;
properties.put("mail.smtp.auth", authRequired);
properties.put("mail.smtp.host", "ses smtp hostname");
properties.put("mail.smtp.port", 25);
properties.put("mail.smtp.connectiontimeout", 10000);
properties.put("mail.smtp.timeout", 10000);
properties.put("mail.smtp.starttls.enable", false);
properties.put("mail.smtp.starttls.required", false);
Session session;
if (authRequired) {
session = Session.getInstance(properties, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("ses_username","ses_password");
}
});
} else {
session = Session.getDefaultInstance(properties);
}
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("from@example.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to@example.com"));
message.setSubject("This is a test subject");
Multipart multipart = new MimeMultipart();
BodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent("This is test content", "text/html");
htmlPart.setDisposition(BodyPart.INLINE);
multipart.addBodyPart(htmlPart);
message.setContent(multipart);
Transport.send(message);
} catch (Exception e) {
//deal with errors
}