views:

384

answers:

4

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

+1  A: 

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
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
+1  A: 

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
A: 

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
A: 

You can see my blog post here at http://codersatwork.wordpress.com/2010/02/14/sending-email-using-gmail-smtp-server-and-spring-mail/ which explains how to use spring mail for sending email via gmail smtp server. Please let me know if this helps.

Saurabh

Saurabh