2017-08-17 93 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

多部分的事情幫助我擺脫了垃圾郵件問題 –

相關問題