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

Spring Security, OpenId and special characters

I wanted to enable open id login with spring security 3.0.7. I’ve used google as a open id provider.
Setup was pretty easy, everything by the book. I’ve tried with couple of accounts and everything was ok.

But when I tried to use my “official” google account, I’ve ran into a problem. My account couldn’t pass the verification. In log files I’ve found this:

Verification failed for: [http://somedomain] reason: null

Reason null. Whoa, too much information :)

Googling didn’t help much, until I’ve realized that the problem was in encoding. Yup, all accounts worked except mine… and I have the letter ć in my surname. I guess the same problem would be with umlauts and similar.

The easiest fix was to add just one attribute to the Connector element in server.xml tomcat configuration. The magical attribute is:

URIEncoding="UTF-8"