解決了這個問題。 我不確定發生了什麼,但是當使用SpringBoot JavaMailSenderImpl使用AWS SES發送電子郵件時,所有電子郵件都沒有使用DKIM進行簽名(在外發電子郵件中沒有DKIM標頭)。這導致一些SMTP服務器將我們的電子郵件視爲垃圾郵件。
我已經通過使用Java郵件API(javax.mail)發送電子郵件解決了該問題,並且一旦我完成了該操作,則所有電子郵件都將與DKIM標頭一起提供,並且它們都不會轉到SPAM文件夾(經過測試Gmail和Outlook)。
同樣,我不確定爲什麼使用SpringBoot JavaMailSenderImpl導致該問題。我的理解是,JavaMailSenderImpl在場景後面使用Java Mail,但由於某些原因,電子郵件中沒有包含DKIM標題。
下面是我的電子郵件發件人使用Java郵件,如果它會幫助任何人在那裏。
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
}
嘗試一些在線垃圾郵件測試者,例如http://www.isnotspam.com/。 – Veve