发送失败(javax.mail.MessagingException:无法获取SASL身份验证器)

时间:2014-08-25 11:31:28

标签: javamail tomee james

我有相当独特的设置。我不确定其他人是否尝试过这个。
我有以下VirtualBox设置。
主机是OS X(Maverick)
访客是Windows 7 64位。

我在Guest上运行了一个apache james-2.3.2。我在这个詹姆斯服务器上有几个用户。我还没有配置ssl。我已将DNS设置为我的家庭路由器IP地址。

我的vm上也有端口转发设置。主机端口10025 - >访客端口25.

在主机上我安装了雷鸟。当我从一个帐户向另一个帐户发送电子邮件时,我可以看到其他james用户收到该电子邮件。我使用localhost作为Thunderbird中所有帐户的主机。

现在,我有一个apache tomee在主机上运行,​​需要发送一封电子邮件的ejb。以下是我在tomee.xml中的邮件会话配置

 <Resource
    id="xyz_mail"
    type="javax.mail.Session"
>
    mail.transport.protocol=smtp
    mail.smtp.ssl.enable=false
    mail.smtp.socketFactory.port=10025
    mail.smtp.socketFactory.fallback=false
    mail.smtp.host=localhost
    mail.smtp.port=10025
    mail.smtp.auth=true
    mail.smtp.user=user1
    password=user1
    mail.smtp.password=user1 (added just for the heck of it, things don't work with out without this line)
    mail.smtp.connectiontimeout=5000
    mail.smtp.timeout=5000
</Resource>

我在ejb中的java代码如下

public class NotificationManagerImpl implements NotificationManager {


@Resource(name = "xyz_mail")
Session xyzMailSession;

public void sendMessage(String addressTo, String subject, String messageText) {
    try {
        logger.info("Attempting to send Message to [" + addressTo + "].");
        properties.getProperty("mail.smtp.user"), properties.getProperty("password"));
        Message message = new MimeMessage(xyzMailSession);
        message.setFrom(new InternetAddress("user2@abctech.com"));
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(addressTo));
        message.setSubject(subject);
        message.setText(messageText);
        abcMailSession.setDebug(true);
        Transport.send(message);
        logger.info("Message sent to [" + addressTo + "] successfully.");

    } catch (Exception e) {
        logger.log(Level.SEVERE, "Error when sending an email", e);
        throw new RuntimeException(e);
    }
}

此代码无法发送电子邮件。以下是调试输出和异常 我的问题是,当Thunderbird能够发送和接收电子邮件时,为什么会出现此错误?
这是我在telnet时看到的

MacBook-Pro:ayx_mobile ajayamrite$ telnet localhost 10025
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

JavaMail参考实现错误

DEBUG: setDebug: JavaMail version 1.5.2
#
#Sun Aug 31 22:00:31 BST 2014
mail.smtp.socketFactory.fallback=false
mail.smtp.ssl.enable=false
mail.transport.protocol=smtp
mail.smtp.connectiontimeout=5000
mail.smtp.host=localhost
mail.smtp.timeout=5000
mail.smtp.port=10025
mail.smtp.auth=true
mail.smtp.socketFactory.port=10025
mail.smtp.user=xyz
password=xyz
mail.smtp.password=xyz
ServiceId=xyz_mail
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true

DEBUG: SMTPTransport trying to connect to host "localhost", port 10025

DEBUG SMTP RCVD: 
DEBUG: SMTPTransport could not connect to host "localhost", port: 10025

Aug 31, 2014 10:00:36 PM abc.NotificationManagerImpl sendMessage
SEVERE: Error when sending an email
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 10025
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:899)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:158)
at javax.mail.Service.connect(Service.java:364)
at javax.mail.Service.connect(Service.java:245)
at abc.NotificationManagerImpl.sendMessage(NotificationManagerImpl.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)

geronimo实施时出错。

Loading javamail.default.providers from jar:file:/Users/ajayamrite/Downloads/apache-tomee-abc-core/lib/geronimo-javamail_1.4_mail-1.8.2.jar!/META-INF/javamail.default.providers
DEBUG: loading new provider protocol=smtp, className=org.apache.geronimo.javamail.transport.smtp.SMTPTransport, vendor=Apache Software Foundation, version=1.0
DEBUG: loading new provider protocol=smtps, className=org.apache.geronimo.javamail.transport.smtp.SMTPSTransport, vendor=Apache Software Foundation, version=1.0
DEBUG: loading new provider protocol=nntp-post, className=org.apache.geronimo.javamail.transport.nntp.NNTPTransport, vendor=Apache Software Foundation, version=1.0
DEBUG: loading new provider protocol=nntp-posts, className=org.apache.geronimo.javamail.transport.nntp.NNTPSSLTransport, vendor=Apache Software Foundation, version=1.0
DEBUG: loading new provider protocol=nntp, className=org.apache.geronimo.javamail.store.nntp.NNTPStore, vendor=Apache Software Foundation, version=1.0
DEBUG: loading new provider protocol=nntps, className=org.apache.geronimo.javamail.store.nntp.NNTPSSLStore, vendor=Apache Software Foundation, version=1.0
DEBUG: loading new provider protocol=pop3, className=org.apache.geronimo.javamail.store.pop3.POP3Store, vendor=Apache Software Foundation, version=1.0
DEBUG: loading new provider protocol=pop3s, className=org.apache.geronimo.javamail.store.pop3.POP3SSLStore, vendor=Apache Software Foundation, version=1.0
DEBUG: loading new provider protocol=imap, className=org.apache.geronimo.javamail.store.imap.IMAPStore, vendor=Apache Software Foundation, version=1.0
DEBUG: loading new provider protocol=imaps, className=org.apache.geronimo.javamail.store.imap.IMAPSSLStore, vendor=Apache Software Foundation, version=1.0 Loading javamail.default.providers from jar:file:/Users/ajayamrite/Downloads/apache-tomee-abc-core/apps/abcCoreEAR/lib/javax.mail_1.4.0.v201005080615.jar!/META-INF/javamail.default.providers
DEBUG: loading new provider protocol=smtp, className=org.apache.geronimo.javamail.transport.smtp.SMTPTransport, vendor=Apache Software Foundation, version=1.0
DEBUG: loading new provider protocol=smtps, className=org.apache.geronimo.javamail.transport.smtp.SMTPTSransport, vendor=Apache Software Foundation, version=1.0
DEBUG: loading new provider protocol=nntp-post, className=org.apache.geronimo.javamail.transport.nntp.NNTPTransport, vendor=Apache Software Foundation, version=1.0
DEBUG: loading new provider protocol=nntp, className=org.apache.geronimo.javamail.store.nntp.NNTPStore, vendor=Apache Software Foundation, version=1.0
DEBUG: loading new provider protocol=pop3, className=org.apache.geronimo.javamail.store.pop3.POP3Store, vendor=Apache Software Foundation, version=1.0
Loading javamail.default.providers from jar:file:/Users/ajayamrite/Downloads/apache-tomee-abc-core/apps/abcCoreEAR/mail.jar!/META-INF/javamail.default.providers
DEBUG: loading new provider protocol=imap, className=com.sun.mail.imap.IMAPStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=smtp, className=com.sun.mail.smtp.SMTPTransport, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=pop3, className=com.sun.mail.pop3.POP3Store, vendor=Sun Microsystems, Inc, version=null
DEBUG: getProvider() returning provider protocol=smtp; type=javax.mail.Provider$Type@4c3b0d83; class=org.apache.geronimo.javamail.transport.smtp.SMTPTransport; vendor=Apache Software Foundation;version=1.0
smtp DEBUG: Failing connection for missing authentication information

smtp DEBUG: Attempting plain socket connection to server 127.0.0.1:10025
220 bedouinvm SMTP Server (JAMES SMTP Server 2.3.2) ready Mon, 25 Aug 2014 11:53:29 +0100 (BST)
EHLO Ajays-MacBook-Pro.local
250-bedouinvm Hello Ajays-MacBook-Pro.local (10.0.3.2 [10.0.3.2])
250-PIPELINING
250 ENHANCEDSTATUSCODES
smtp DEBUG: Processing extension PIPELINING
smtp DEBUG: Processing extension ENHANCEDSTATUSCODES
QUIT
221 2.0.0 bedouinvm Service closing transmission channel
Aug 25, 2014 11:53:29 AM co.uk.abc.core.interfaces.impl.NotificationManagerImpl sendMessage
SEVERE: Error when sending an email javax.mail.SendFailedException: Send failure (javax.mail.MessagingException: Unable to obtain SASL authenticator)
at javax.mail.Transport.send(Transport.java:163)
at javax.mail.Transport.send(Transport.java:48)
at co.uk.abc.core.interfaces.impl.NotificationManagerImpl.sendMessage(NotificationManagerImpl.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:182)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:164)
at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:180)
at org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:182)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:164)
at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:80)
at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:212)
at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:181)
at org.apache.openejb.server.ejbd.EjbRequestHandler.doEjbObject_BUSINESS_METHOD(EjbRequestHandler.java:370)
at org.apache.openejb.server.ejbd.EjbRequestHandler.processRequest(EjbRequestHandler.java:181)
at org.apache.openejb.server.ejbd.EjbDaemon.processEjbRequest(EjbDaemon.java:344)
at org.apache.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:240)
at org.apache.openejb.server.ejbd.EjbServer.service(EjbServer.java:86)
at org.apache.openejb.server.httpd.ServerServlet.service(ServerServlet.java:58)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

3 个答案:

答案 0 :(得分:0)

尝试使用JavaMail reference implementation而不是GNU版本。

答案 1 :(得分:0)

在预感中,我暂时关闭了客户Windows 7计算机上的防火墙。电子邮件发送有效,因此客人的防火墙导致了问题。

我再次打开防火墙(不要忘记这样做)并在来宾上创建一个入站规则以允许连接到端口25(仅限我的专用网络)。

电子邮件发送现在正常运行。

答案 2 :(得分:0)

尝试使用以下命令行选项:-Djava.net.preferIPv4Stack = true

它为我解决了类似的连接问题。