Spring - config spring email

I used springmail to send email from my smtp server with the following configuration:

<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 he throws "javax.net.ssl.SSLException: unrecognized SSL message, plaintext connection?" I tested this configuration with gmail on port 465 and it worked.

Please tell me what I did wrong. thank you

+1
source share
3 answers

It looks like your SMTP server requires an SSL (secure) connection. See the example below on how to configure it for Gmail, which also requires SSL. Pay attention to the smtps protocol and additional properties.

<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>
+5
source

, SSL. ? , .

, .

+1

javaMailProperties, .

duffymo, , , SSL ( 25 - SMTP- SSL). SMTP- ( ).

0

Source: https://habr.com/ru/post/1732643/


All Articles