解决了这个问题。
我不确定到底发生了什么,但是当使用 SpringBoot JavaMailSenderImpl 使用 AWS SES 发送电子邮件时,所有电子邮件都没有使用 DKIM 签名(传出电子邮件消息上没有 DKIM 标头)。这导致一些 SMTP 服务器将我们的电子邮件视为垃圾邮件。
我已经通过使用 Java Mail API (javax.mail) 发送电子邮件解决了这个问题,一旦我这样做了,那么所有电子邮件都使用 DKIM 标头传递,并且没有一个进入垃圾邮件文件夹(针对 Gmail 进行了测试和展望)。
再次,我不确定为什么使用 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
}