1

我只是通过 gmail 帐户向用户发送电子邮件。在我的开发环境(Windows 7)中一切正常,但是当我转向生产 ubuntu 时,它会抛出以下异常

java.lang.RuntimeException: org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException
at com.product.mailservice.MailServiceImpl.sendMail(MailServiceImpl.java:90)

这是我的配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="javaMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="password" value="xxxxxxx"></property>
    <property name="username" value="xxxxxx@gmail.com"></property>
    <property name="javaMailProperties">
        <props>
            <prop key="mail.smtp.auth">true</prop>
            <prop key="mail.debug">false</prop>
            <prop key="mail.smtp.host">smtp.gmail.com</prop>
            <prop key="mail.smtp.socketFactory.port">465</prop>
            <prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
            <prop key="mail.smtp.starttls.enable">true</prop>
            <prop key="mail.smtp.port">465</prop>
            <prop key="mail.smtp.user">xxxxxx@gmail.com</prop>
            <prop key="mail.smtp.password">xxxxxxx</prop>
            <prop key="mail.smtp.ssl.enable">true</prop>
        </props>
    </property>
</bean>

<bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage">
    <property name="from">
        <value>xxxxxx@gmail.com</value>
    </property>
    <property name="subject">
        <value>Password Notification</value>
    </property>
</bean>

<bean id="mailService" class="com.product.mailservice.MailServiceImpl">
    <property name="javaMailSender" ref="javaMailSender" />
    <property name="templateMessage" ref="templateMessage" />
</bean>

更新。这是调试信息

DEBUG: JavaMail version 1.4ea DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.6.0_21\jre\lib\javamail.providers (系统找不到指定的文件) DEBUG: !anyLoaded DEBUG: not加载资源:/META-INF/javamail.providers 调试:成功加载资源:/META-INF/javamail.default.providers 调试:加载的提供程序表调试:按类名列出的提供程序:{com.sun.mail.smtp. SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com. sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail。 pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]} 调试:按协议列出的提供程序:{imaps=javax.mail.Provider[STORE,imaps, com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail。 Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,太阳微系统,Inc]} 调试:成功加载资源:/META-INF/javamail.default.address.map 调试:!anyLoaded 调试:未加载资源:/META-INF/javamail.address.map 调试:java.io.FileNotFoundException:C :\Program Files\Java\jdk1.6.0_21\jre\lib\javamail.address.map (系统找不到指定的文件) DEBUG: getProvider() 返回 javax.mail.Provider[TRANSPORT,smtp,com.sun. mail.smtp.SMTPTransport,Sun Microsystems, Inc] 调试 SMTP:useEhlo true,useAuth true 调试 SMTP:尝试连接主机“smtp.gmail.com”,端口 465,isSSL falsegetProvider() 返回 javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc] 调试 SMTP:useEhlo true,useAuth true 调试 SMTP:尝试连接到主机“smtp.gmail。 com", 端口 465, isSSL falsegetProvider() 返回 javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc] 调试 SMTP:useEhlo true,useAuth true 调试 SMTP:尝试连接到主机“smtp.gmail。 com", 端口 465, isSSL false

4

0 回答 0