• A+

Spring:Could not connect to SMTP host: smtp.qq.com, port: 465...

由于现在安全策略的改变,以往的邮箱代理设置方式已经不适用,javax.net.ssl.SSLSocketFactory一定要设置

 <!--开启组件扫描,通过注解声明bean自动装配-->
    <context:component-scan base-package="club.logicr.myweb"/>
    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="smtp.qq.com" />
        <property name="port" value="465" />
        <property name="username" value="username" />
        <property name="password" value="授权码" />
        <property name="protocol" value="smtp"/>
        <property name="javaMailProperties">
            <props>
                <!-- 设置认证开关 -->
                <prop key="mail.smtp.auth">true</prop>
                <!-- 启动调试开关 -->
                <prop key="mail.debug">true</prop>
                <!-- 设置发送延时 -->
                <prop key="mail.smtp.timeout">0</prop>
                <prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
                <prop key="mail.smtp.socketFactory.port">465</prop>
            </props>

        </property>
    </bean>

 


注意:本文归作者所有,未经作者允许,不得转载
所属分类:博客

全部评论: 0

    我有话说:
    ×