A j
A j

Reputation: 1097

Send failure (javax.mail.MessagingException: Unable to obtain SASL authenticator)

I have rather unique setup. I am not sure if others have tried this.
I have the following VirtualBox setup.
Host is a OS X (Maverick)
Guest is Windows 7 64 bit.

I have an apache james-2.3.2 running on the Guest. I have several users on this james server. I have not configured ssl. I have set the DNS to be my home routers ip address.

I also have port forwarding setup on my vm. Host port 10025 -> Guest port 25.

On the host I have installed thunder bird. When I send email from one account to the other I can see the other james user receiving the email. I have use localhost as the host for all my accounts in Thunderbird.

Now, I have a apache tomee running on the host with an ejb that needs to send out an email. Following is my config for the mail session in 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>

My java code in the ejb is the following

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("[email protected]"));
        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);
    }
}

This code fails to send out an email. Following is the debug output and Exception.
My question is why do I get this error when Thunderbird is able to send and receive emails just fine?
This what I see when I do telnet

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

Error with JavaMail reference implementation

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)

Error with geronimo implementation.

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)

Upvotes: 2

Views: 6011

Answers (3)

Fox
Fox

Reputation: 1

Try to use the following command line option: -Djava.net.preferIPv4Stack=true

It solved a similar connection issue for me.

Upvotes: 0

A j
A j

Reputation: 1097

On a hunch I turned off the firewall on the guest Windows 7 machine briefly. The email sending worked, so it was the firewall on the guest that was causing problems.

I turned on the firewall again (Don't forget to do this) and created a Inbound Rule on the guest to allow connections to the port 25 (only on my private network).

The email sending is now working properly.

Upvotes: 0

Bill Shannon
Bill Shannon

Reputation: 29971

Try using the JavaMail reference implementation instead of the GNU version.

Upvotes: 1

Related Questions