2011-12-21 119 views
11

我想發送電子郵件與亞馬遜的SES/SMTP,我收到以下錯誤:無法連接到SMTP主機:email-smtp.us-east-1.amazonaws.com,端口:465,迴應:-1

javax.mail.MessagingException的:無法連接到SMTP主機:email-smtp.us-east-1.amazonaws.com,端口:465,響應:-1

這裏我如何嘗試發送郵件:

春季郵件發件人配置:

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> 
     <property name="host" value="${mail.server}"/> 
     <property name="port" value="${mail.port}"/> 
     <property name="username" value="${aws.mail.smtp.user}"/> 
     <property name="password" value="${aws.mail.smtp.password}"/> 
     <property name="javaMailProperties"> 
      <props> 
      <!-- Use SMTP-AUTH to authenticate to SMTP server --> 
      <prop key="mail.smtp.auth">true</prop> 
      <!-- Use TLS to encrypt communication with SMTP server --> 
      <prop key="mail.smtp.starttls.enable">true</prop> 
      </props>  
     </property> 
    </bean> 

有:

mail.server =email-smtp.us-east-1.amazonaws.com 
mail.port = 465 

回答

12

與Amazon SES,配置需要如下:

<prop key="mail.smtp.auth">true</prop>  
<prop key="mail.smtp.ssl.enable">true</prop> 

代替:

<prop key="mail.smtp.auth">true</prop> 
<prop key="mail.smtp.starttls.enable">true</prop> 

由Dave作爲暗示。

編輯:請使用此解決方案:https://stackoverflow.com/a/8928559/536299

+0

我不認爲這個答案中的代碼片段是正確的(例如,應該是「mail.smtps.auth」),但鏈接中的信息很好,並會幫助您找到答案。 – fivedogit 2016-09-27 15:40:06

4

亞馬遜SES SMTP需要SMTP會話之前的SSL。 StartTLS命令不受SES支持。

+0

感謝戴夫,我也試圖設置* mail.smtp.starttls.enable *爲false無濟於事。你有其他想法嗎? – balteo 2011-12-23 15:22:03

0

這名僱員從AWS指出SES不支持SSL的。 https://forums.aws.amazon.com/message.jspa?messageID=218303

Amazon SES will attempt to send email with Transport Layer Security enabled, but there is not a way to guarantee messages are sent with TLS. SES uses opportunistic TLS when sending emails, which means it will attempt to send emails over TLS first, and then will fall back to regular SMTP if TLS is unavailable.

因此,我認爲你看到的問題不是TLS或SSL相關的問題,而是其他問題。

+0

這顯然不再是這種情況 - 我必須*啓用* SSL才能讓電子郵件再次與我的Railo服務器一起工作。 – 2016-02-23 23:54:49

0
Properties props = new Properties(); 
props.setProperty("mail.transport.protocol", "smtp"); 
props.setProperty("mail.smtp.auth", "true"); 
props.setProperty("mail.host", "email-smtp.us-east-1.amazonaws.com"); 
props.setProperty("mail.user", "your_ses_user"); 
props.setProperty("mail.password", "your_ses_pwd"); 



Session mailSession = Session.getDefaultInstance(props, new Authenticator(){ 
    public PasswordAuthentication getPasswordAuthentication() { 
     String username = "your_ses_user"; 
     String password = "your_ses_pwd"; 
     return new PasswordAuthentication(username, password); 
    } 
}); 

這些代碼已經過測試,效果很好。 如果你想使用SMTP通過SSL,請配置:

props.setProperty("mail.smtp.starttls.enable", "true"); 

或者你可以從HERE下載AWS的Java SDK。

代碼示例是HERE

1

這些設置爲我工作:

mail.transport.protocol=smtp 
mail.smtp.port=25 
mail.smtp.auth=true 
mail.smtp.starttls.enable=true 
mail.smtp.starttls.required=true 
mail.smtp.host=email-smtp.us-east-1.amazonaws.com 
mail.smtp.user=[SMTP username] 
mail.smtp.password=[SMTP user password] 

如果你試圖連接使用SSL連接來連接,它拒絕連接。所以你需要在連接後做STARTTLS。

您可以添加mail.debug = true以查看失敗的位置。

發件人的電子郵件地址必須是經過驗證的電子郵件地址,否則SES拒絕轉發該電子郵件。

相關問題