如何使用 SMTP 为 SES 配置 Spring JavaMailSender? [英] How to configure Spring JavaMailSender for SES using SMTP?

查看:111
本文介绍了如何使用 SMTP 为 SES 配置 Spring JavaMailSender?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试配置 Spring JavaMailSender 以使用 SMTP 与 Amazon 的 SES 服务一起工作,但我们收到此错误:

We are trying to configure Spring JavaMailSender to work with Amazon's SES service using SMTP, but we are getting this error:

javax.mail.MessagingException: Could not connect to SMTP host: email-smtp.us-east-1.amazonaws.com, port: 465, response: -1

这是我们的配置:

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="email-smtp.us-east-1.amazonaws.com" />
    <property name="port" value="465" />
    <property name="username" value="..." />
    <property name="password" value="..." />
    <property name="javaMailProperties">
        <props>
            <prop key="mail.smtp.auth">true</prop>
            <prop key="mail.smtp.ssl.enable">true</prop>
        </props>
    </property>
</bean>

任何想法可能是错误的?提前致谢.

Any ideas what could be wrong? Thanks in advance.

PS:我们已经在这里尝试了解决方案:无法连接到 SMTP 主机:email-smtp.us-east-1.amazonaws.com,端口:465,响应:-1 没有任何运气.

PS: We already tried the solution here: Could not connect to SMTP host: email-smtp.us-east-1.amazonaws.com, port: 465, response: -1 without any luck.

推荐答案

基于@GuCo 回答:这是对我有用的完整配置:

Based on @GuCo answer: This is the full configuration that worked for me:

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="email-smtp.us-east-1.amazonaws.com" />
    <property name="port" value="465" />
    <property name="protocol" value="smtps" />
    <property name="username" value="..." />
    <property name="password" value="..." />
    <property name="javaMailProperties">
        <props>
            <prop key="mail.smtps.auth">true</prop>
            <prop key="mail.smtp.ssl.enable">true</prop>
            <prop key="mail.transport.protocol">smtps</prop>
        </props>
    </property>
</bean>

不要忘记<property name="protocol" value="smtps"/>配置,否则javaMailProperties不会被考虑.

Do not forget the <property name="protocol" value="smtps" /> configuration, or else the javaMailProperties are not taken into consideration.

这篇关于如何使用 SMTP 为 SES 配置 Spring JavaMailSender?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆