Spring Java Mail gmail smtp无法在Ubuntu中运行

时间:2013-07-16 06:27:29

标签: java spring smtp javamail smtp-auth

我只是通过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版本1.4ea DEBUG:java.io.FileNotFoundException:C:\ Program Files \ Java \ jdk1.6.0_21 \ jre \ lib \ javamail.providers(系统找不到指定的文件) DEBUG:!anyLoaded DEBUG:没有加载资源:/META-INF/javamail.providers DEBUG:成功加载资源:/META-INF/javamail.default.providers DEBUG:加载的提供者表 调试:按类名列出的提供商:{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]} DEBUG:按协议列出的提供商:{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,Sun Microsystems,Inc]} DEBUG:成功加载资源:/META-INF/javamail.default.address.map DEBUG:!anyLoaded DEBUG:不加载资源:/META-INF/javamail.address.map DEBUG: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] DEBUG SMTP:useEhlo true,useAuth true DEBUG SMTP:尝试连接主机“smtp.gmail.com”,端口465,isSSL false

0 个答案:

没有答案