1

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

<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?" I've tested this config with gmail on port 465 and it worked.

Please tell me what i've done wrong. Thank you

robinmag
  • 17,520
  • 19
  • 54
  • 55
  • There are an answer for this question http://stackoverflow.com/questions/8917400/how-to-configure-spring-javamailsender-for-ses-using-smtp – Yuriy Semen Oct 08 '13 at 15:28

3 Answers3

6

It looks like your SMTP server requires SSL (secure) connection. See example below of how to configure it for Gmail, which is also requires SSL. Note smtps protocol and extra 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>
maximdim
  • 8,041
  • 3
  • 33
  • 48
1

Maybe you shouldn't be using 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.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • Thank you, i've removed these properties mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory mail.smtp.socketFactory.fallback=false But it gives me another exeption : MessagingException: [EOF] – robinmag Dec 24 '09 at 03:57
  • I removed mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory mail.smtp.socketFactory.fallback=false and it worked – Piyush Sep 10 '19 at 05:23
0

I would try removing all javaMailProperties, as well as the username and password properties.

As duffymo points out, you probably shouldn't use SSL (port 25 is the non-SSL SMTP port). Most SMTP servers also don't require authentication (unless you've explicitly configured it).

Jack Leow
  • 21,945
  • 4
  • 50
  • 55