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.

Advertisement