2011-12-21 854 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拒绝转发该电子邮件。

相关问题