Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Mail Authentication Error

I am using spring 3.1 in my project and in order to send email, I am using spring mail. When I am trying to send an email, I aıways get this error:

org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: No authentication mechansims supported by both server and client

My mail server does not require a username/ password and this error seems normal according to this fact. But the case is; I could not find a way to not to pass username/password in spring mail's org.springframework.mail.javamail.JavaMailSenderImpl class.

My config is :

<jee:jndi-lookup id="mailSession" jndi-name="${abc.app.mailSession}" cache="true"/>

    <bean id="jndiMailSender" class="com.abc.service.mail.JndiJavaMailService">
        <property name="session" ref="mailSession"/>
        <property name="defaultEncoding" value="${mail.defaultEncoding}"/>
        <property name="username" value="${abc.mail.username}"/>
        <property name="password" value="${abc.mail.password}"/>
        <property name="mailMasterAdress" value="${abc.mail.mailMasterAdress}"/>
    </bean>

Mailserver is in weblogic and it's configs are:

mail.smtp.host=10.200.123.135 mail.transport.protocol=smtp

Any ideas?

like image 599
Neron Avatar asked Sep 03 '13 06:09

Neron


3 Answers

Use these properties:

mail.host=smtp.gmail.com
mail.port=587
mail.username=<[email protected]>
mail.password=<gmail-password>
mail.transport.protocol=smtp
mail.smtp.auth=true
mail.smtp.starttls.enable=true
mail.from.email=<[email protected]>

By default, gmail does not allow less secure apps to get authenticated. You need to turn on the option in you gmail account to allow less secure apps to get authenticated.

Follow these steps:

1.Login to Gmail. 
2.Access the URL as https://www.google.com/settings/security/lesssecureapps 
3.Select "Turn on"

Try running your code again, it should work.

like image 158
sjaiswal Avatar answered Nov 09 '22 14:11

sjaiswal


Use below configuration:

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="smtp.gmail.com"/>
    <property name="port" value="25"/>
    <property name="username" value="[email protected]"/>
    <property name="password" value="xxxxxxxxx"/>
    <property name="javaMailProperties">
        <props>
            <prop key="mail.transport.protocol">smtp</prop>
            <prop key="mail.smtp.auth">true</prop>
            <prop key="mail.smtp.starttls.enable">true</prop>
            <prop key="mail.debug">true</prop>
        </props>
    </property>
</bean>

and follow below procedure:

  1. Login to Gmail.
  2. Access the URL as https://www.google.com/settings/security/lesssecureapps
  3. Select "Turn on"
like image 23
Sandip S. Avatar answered Nov 09 '22 15:11

Sandip S.


This worked for me:

Bean Cofiguration

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="smtp.gmail.com" />
    <property name="port" value="587" />
    <property name="username" value="<!--Gmail ID -->" />
    <property name="password" value="<!-- Gmail Password -->" />

    <!-- The name of the property, following JavaBean naming conventions -->
    <property name="javaMailProperties">
        <props>
            <prop key="mail.transport.protocol">smtp</prop>
            <prop key="mail.smtp.auth">true</prop>
            <prop key="mail.smtp.starttls.enable">true</prop>
            <prop key="mail.debug">true</prop>
        </props>
    </property>
</bean>

Secondly, you need to turn on the access for less secure apps.

1. Login to Gmail. 
2. Access the URL as https://www.google.com/settings/security/lesssecureapps 
3. Select "Turn on"
like image 27
Pradip Kharbuja Avatar answered Nov 09 '22 14:11

Pradip Kharbuja