Sun Java System Application Server 9.1 和 Postfix 邮件服务器出现 javax.mail.AuthenticationFailedException
在我的应用程序中,我有以下消息驱动 Bean 连接到 Postfix SMTP 服务器以向用户发送电子邮件:
@MessageDriven(mappedName = "jms/OutgoingEmailQueue", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class OutgoingEmailBean implements MessageListener {
//Resource
@Resource(name = "mail/MailSession")
private Session mailSession;
public void onMessage(Message message) {
try {
....
//Create the email
javax.mail.Message email = new MimeMessage(mailSession);
....
//Send the email
Transport.send(email);
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
当我在笔记本电脑上使用 NetBeans 和 GlassFish 2.1 部署此应用程序时,它可以连接到 SMTP 服务器并完美发送电子邮件。但是,当我将所有设置复制到在线 Sun Java System Application Server 9.1 并部署应用程序时,我的应用程序无法再发送电子邮件。相反,我在“Transport.send(email)”行收到异常 javax.mail.AuthenticationFailedException。在服务器日志中,我看到了这些行:
[#|2011-08-01T15:18:02.077+0400|SEVERE|sun-appserver9.1|ejb.Mailing.OutgoingEmailBean|_ThreadID=34;_ThreadName=p: thread-pool-1; w: 665;_RequestID=52699cfe-71a2-46be-83b0-f3af23d74c0c;|The log message is null.
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:319)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at ejb.Mailing.OutgoingEmailBean.onMessage(OutgoingEmailBean.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)
at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3986)
at com.sun.ejb.containers.MessageBeanContainer.deliverMessage(MessageBeanContainer.java:1111)
at com.sun.ejb.containers.MessageBeanListenerImpl.deliverMessage(MessageBeanListenerImpl.java:74)
at com.sun.enterprise.connectors.inflow.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:179)
at $Proxy93.onMessage(Unknown Source)
at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:258)
at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:76)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
|#]
我花了 2 天环顾四周,以确保 GlassFish 2.1 的所有本地设置与在线应用程序服务器的设置相同,但我仍然无法解决问题。如果有人能给我关于如何解决这个问题的建议,我将不胜感激。
最好的问候,
詹姆斯·特兰
In my application, I have the following Message Driven Bean to connect to the Postfix SMTP server to send emails to user:
@MessageDriven(mappedName = "jms/OutgoingEmailQueue", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class OutgoingEmailBean implements MessageListener {
//Resource
@Resource(name = "mail/MailSession")
private Session mailSession;
public void onMessage(Message message) {
try {
....
//Create the email
javax.mail.Message email = new MimeMessage(mailSession);
....
//Send the email
Transport.send(email);
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
When I deploy this application using NetBeans with GlassFish 2.1 on my laptop, it can connect to the SMTP server and send out emails perfectly. However, when I copy all the settings over to the online Sun Java System Application Server 9.1 and deploy my application, my application no longer can send out emails. Instead, I got the exception javax.mail.AuthenticationFailedException at the line "Transport.send(email)". In the server log, I saw these lines:
[#|2011-08-01T15:18:02.077+0400|SEVERE|sun-appserver9.1|ejb.Mailing.OutgoingEmailBean|_ThreadID=34;_ThreadName=p: thread-pool-1; w: 665;_RequestID=52699cfe-71a2-46be-83b0-f3af23d74c0c;|The log message is null.
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:319)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at ejb.Mailing.OutgoingEmailBean.onMessage(OutgoingEmailBean.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)
at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3986)
at com.sun.ejb.containers.MessageBeanContainer.deliverMessage(MessageBeanContainer.java:1111)
at com.sun.ejb.containers.MessageBeanListenerImpl.deliverMessage(MessageBeanListenerImpl.java:74)
at com.sun.enterprise.connectors.inflow.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:179)
at $Proxy93.onMessage(Unknown Source)
at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:258)
at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:76)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
|#]
I spent 2 days looking around to make sure all the local settings of GlassFish 2.1 are identical to the settings of the online appserver but I still cannot solve the problem. I'd be very grateful if someone could give me an advice on how to tackle this issue.
Best regards,
James Tran
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现在 Postfix 配置中,“mynetworks”属性不包含我的域的 IP 地址。添加IP地址后,我的应用程序已经可以正常发送电子邮件了。
I found out that in Postfix configuration, "mynetworks" property didn't include the IP address of my domain. After adding the IP address, my application can send out emails normally already.