Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to find the correct properties to use to connect to the Gmail SMTP sever using the JavaMailSenderImpl class.

Let me first say that I have tried the approach found here. This worked fine. But when I tried the configuration below that post with the exact same authentication information I received a javax.mail.AuthenticationFailedException.

My currently configuration looks like this.

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

Why am I still getting this javax.mail.AuthenticationFailedException if I know that my credentials are correct.

Update

Here is my updated code based on the answers below. I am still receiving the same exception.

<bean id="mailSender" class ="org.springframework.mail.javamail.JavaMailSenderImpl" >
    <property name="username" value="[email protected]" />
    <property name="password" value="XXX" />
    <property name="javaMailProperties">
    <props>
        <prop key="mail.smtp.from">[email protected]</prop>
        <prop key="mail.smtp.user">[email protected]</prop>
        <prop key="mail.smtp.password">XXX</prop>
        <prop key="mail.smtp.host">smtp.gmail.com</prop>
        <prop key="mail.smtp.port">587</prop>
        <prop key="mail.smtp.auth">true</prop>
        <prop key="mail.smtp.starttls.enable">true</prop>
    </props>
    </property>
</bean>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
122 views
Welcome To Ask or Share your Answers For Others

1 Answer

This worked for me:

        <property name="host"><value>smtp.gmail.com</value></property>
        <property name="port"><value>587</value></property>
        <property name="protocol"><value>smtp</value></property>
        <property name="username"><value>${mail.username}</value></property>
        <property name="password"><value>${mail.password}</value></property>
        <property name="javaMailProperties">
            <props>
                <prop key="mail.smtp.auth">true</prop>
                <prop key="mail.smtp.starttls.enable">true</prop>
                <prop key="mail.smtp.quitwait">false</prop>
            </props>
        </property>

The real trick for me turned out to be that the "protocol" value has to be "smtp" (not "smtps").


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...