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
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.