JavaMail, Spring and Google apps mail

Whoa, second post in one day :)

In my application I want to use spring’s mail sender with my google apps account. I was getting:

org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first

After a little bit of help form my dear friend, I found out that all you need to do is:

<bean id="javaMailSender">
   <property name="host" value="${mailer.host}"/>
   <property name="username" value="${mailer.user}"/>
   <property name="password" value="${mailer.pass}"/>

   <property name="defaultEncoding" value="${mailer.encoding}"/>

   <property name="javaMailProperties">
      <props>
         <prop key="mail.smtp.auth">true</prop>
         <prop key="mail.smtp.starttls.enable">true</prop>
      </props>
   </property>
</bean>

Take a look at the javaMailProperties element. Yup. That’s all you need to add to your configuration xml.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s