简体   繁体   English

spring-配置春季电子邮件

[英]spring - config spring email

I used the springmail to send email from my smtp server with the following config: 我使用springmail通过以下配置从我的smtp服务器发送电子邮件:

<bean id="springEmailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="defaultEncoding" value="UTF-8"/>
    <property name="host" value="mail.myserver.com"/>
    <property name="port" value="25"/>

    <property name="username" value="username"/>
    <property name="password" value="password"/>
    <property name="javaMailProperties">
        <value> 
            mail.debug=true 
            mail.smtp.auth=true
            mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
            mail.smtp.socketFactory.fallback=false 
        </value>
    </property></bean>

But it throw "javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?" 但是它抛出“ javax.net.ssl.SSLException:无法识别的SSL消息,纯文本连接?” I've tested this config with gmail on port 465 and it worked. 我已经在端口465上用gmail测试了此配置,并且可以正常工作。

Please tell me what i've done wrong. 请告诉我我做错了什么。 Thank you 谢谢

It looks like your SMTP server requires SSL (secure) connection. 看来您的SMTP服务器需要SSL(安全)连接。 See example below of how to configure it for Gmail, which is also requires SSL. 请参阅下面的示例,了解如何为Gmail配置它(这也需要SSL)。 Note smtps protocol and extra properties. 注意smtps协议和其他属性。

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="smtp.gmail.com" />
    <property name="port" value="465" />
    <property name="protocol" value="smtps" />
    <property name="username" value="user"/>
    <property name="password" value="password"/>
    <property name="javaMailProperties">
        <props>
            <prop key="mail.smtps.auth">true</prop>
            <prop key="mail.smtps.starttls.enable">true</prop>
            <prop key="mail.smtps.debug">true</prop>
        </props>
    </property>
</bean>

Maybe you shouldn't be using SSL. 也许您不应该使用SSL。 Is the mail server configured to accept an encrypted message? 邮件服务器是否配置为接受加密的邮件? Looks like it wants plain text. 看起来它想要纯文本。

I'd go back to the reference docs and see if that will work. 我将返回参考文档 ,看看是否可行。

I would try removing all javaMailProperties, as well as the username and password properties. 我会尝试删除所有javaMailProperties以及用户名和密码属性。

As duffymo points out, you probably shouldn't use SSL (port 25 is the non-SSL SMTP port). 正如duffymo指出的那样,您可能不应该使用SSL(端口25是非SSL SMTP端口)。 Most SMTP servers also don't require authentication (unless you've explicitly configured it). 大多数SMTP服务器也不需要身份验证(除非您已明确配置它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM