我相信很多人都问过同样的问题,但我找不到全面的答案。我们正在悉尼地区部署的 EC2 实例上运行 Web 应用程序 (myapp.com)。该应用程序通过 AWS SES 发送电子邮件。由于 SES 在悉尼不可用,我们在俄勒冈州配置了 SES。我们生成了 SMTP 凭据,并将 Springboot 应用程序配置为使用这些凭据发送电子邮件。我们能够发送电子邮件并且电子邮件成功发送,但它进入垃圾邮件文件夹。发件人邮箱地址是:[email protected] 我们在SES控制台验证了域名 我们在SES控制台验证了[email protected]邮箱地址 DKIM也开启验证
但是,我们不确定为什么电子邮件会一直发送到垃圾邮件文件夹。当我查看 RAW 电子邮件消息时,我可以看到 SPF 标头:SPF: NEUTRAL with IP xx.xx.xx.xxx 我没有在我的 DNS 名称中配置任何 SPF 记录,但据我所知,我不需要,因为我使用的是 SES SMTP 服务器而不是自定义 MAIL FROM。
我不知道为什么电子邮件会被发送到垃圾邮件。任何人都可以帮忙吗?
解决了这个问题。我不确定到底发生了什么,但是当使用 SpringBoot JavaMailSenderImpl 使用 AWS SES 发送电子邮件时,所有电子邮件都没有使用 DKIM 签名(外发电子邮件中没有 DKIM 标头)。这导致一些 SMTP 服务器将我们的电子邮件视为垃圾邮件。
我已经通过使用 Java Mail API (javax.mail) 发送电子邮件解决了这个问题,一旦我这样做了,那么所有的电子邮件都带有 DKIM 标头,并且没有一个进入垃圾邮件文件夹(针对 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("[email protected]"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]"));
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
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句