javax.mail。使用Sun Java系统应用服务器9.1和Postfix邮件服务器进行AuthenticationFailedException。

时间:2022-12-07 03:40:18

In my application, I have the following Message Driven Bean to connect to the Postfix SMTP server to send emails to user:

在我的应用程序中,我有以下消息驱动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());
        }
    }
}

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:

当我在我的笔记本电脑上使用NetBeans和GlassFish 2.1来部署这个应用程序时,它可以连接到SMTP服务器并完美地发送电子邮件。然而,当我将所有的设置复制到在线Sun Java系统应用服务器9.1并部署我的应用程序时,我的应用程序就不能再发送电子邮件了。相反,我得到了exception 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)
|#]

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.

我花了2天的时间四处寻找,以确保GlassFish 2.1的所有本地设置与在线appserver的设置完全相同,但我仍然无法解决这个问题。如果有人能给我一个如何解决这个问题的建议,我将不胜感激。

Best regards,

最好的问候,

James Tran

詹姆斯Tran

1 个解决方案

#1


0  

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.

我发现在Postfix配置中,“mynetworks”属性不包括我的域的IP地址。添加IP地址后,我的应用程序可以正常发送电子邮件。

#1


0  

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.

我发现在Postfix配置中,“mynetworks”属性不包括我的域的IP地址。添加IP地址后,我的应用程序可以正常发送电子邮件。