quote

martedì, febbraio 19, 2008

spring mail configuration using gmail as smtp server

If you are going to use gmail as smtp server in your spring configuration file remember to add the property mail.smtp.starttls.enable and set it to true.
Here the configuration of mailSender used in jugevents .

<!-- start mail section -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<!-- here your smtp server -->
<property name="host"><value>smtp.gmail.com</value></property>
<!-- Parameters for SMTP AUTH -->
<property name="username"><value>yourUsername</value></property>
<property name="password"><value>yourPassword</value></property>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<!-- used by gmail smtp server -->
<prop key="mail.smtp.starttls.enable">true</prop>
</props>
</property>
</bean>

Fail doing it you will face into the following exception

org.springframework.mail.MailSendException; nested exception details (1) are: Failed message 1: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first z37sm13522675ikz.1 at

Thanks to Lucio for the help.

9 commenti:

Unknown ha detto...

Very very very very very very very very very very very very very very very very thanks for that post. After searched in many places and thinking in writing a class for do the mail send with TLS, I find it.

Very thank you, man.

enricoGi ha detto...

WOW I am really happy to having helped you to solve your problem. I think it would be good if every developer, after spent some time in solving a bug, would find some time to write the solution in a blog or java website.

Anonimo ha detto...

Muchas gracias por el tip, es muy util

Anonimo ha detto...

Thanks a million!

Joe ha detto...

yeah thats awesome man, thanks a million for that solution!!!

Anonimo ha detto...

Thanks a lot buddy.

Unknown ha detto...

Hi, Thanks for your post.You code helped but I could not get it to work as is.I made some modifications and it worked :



username@gmail.com
password


true

true
465
javax.net.ssl.SSLSocketFactory
false

Anonimo ha detto...

gracias

ilyas ha detto...

Thanks , man it's working