2017-08-17 261 views
1

我相信很多人都问过同样的问题,但我找不到一个全面的答案。 我们正在悉尼地区部署的EC2实例上运行Web应用程序(myapp.com)。该应用程序通过AWS SES发送电子邮件。由于悉尼没有SES,我们在俄勒冈州配置了SES。我们生成了SMTP凭据并配置了我们的Springboot应用程序以使用这些凭证发送电子邮件。我们可以发送电子邮件,并成功发送电子邮件,但它会转到SPAM文件夹。 从地址的电子邮件是:[email protected] 我们在SES控制台 验证过的域名我们在SES控制台 DKIM也开启验证了[email protected]电子邮件地址和验证AWS SES邮件即使在验证后也会经常发送垃圾邮件

但是, 我们不确定为什么电子邮件仍会传送到SPAM文件夹。 当我查看RAW电子邮件时,我可以看到SPF标头: SPF:NEUTRAL IP xx.xx.xx.xxx 我没有在DNS名称中配置任何SPF记录,但据我了解,我没有需要因为我使用SES SMTP服务器而不是自定义MAIL FROM。

我迷失在为什么电子邮件传送到垃圾邮件。 任何人都可以帮忙吗?

+1

尝试一些在线垃圾邮件测试者,例如http://www.isnotspam.com/。 – Veve

回答

1

解决了这个问题。 我不确定发生了什么,但是当使用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 

     } 
+0

多部分的事情帮助我摆脱了垃圾邮件问题 –

相关问题