1

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

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

我的虚拟机上也有端口转发设置。主机端口 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)
4

3 回答 3

1

尝试使用JavaMail 参考实现而不是 GNU 版本。

于 2014-08-27T03:58:15.960 回答
0

凭直觉,我暂时关闭了来宾 Windows 7 机器上的防火墙。电子邮件发送工作正常,因此是来宾上的防火墙引起了问题。

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

电子邮件发送现在正常工作。

于 2014-09-07T07:21:22.447 回答
0

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

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

于 2015-06-01T16:40:40.117 回答