This the code, which works perfect in a unit test (connects to Gmail):
Properties props = new Properties();
props.put("mail.pop3.ssl.enable", true);
props.put("mail.pop3.host", "pop.gmail.com");
props.put("mail.pop3.port", "995");
javax.mail.Session.getDefaultInstance(props, null)
.getStore("pop3")
.connect("foo@...", "password");
When I run the same code in Tomcat7:
...
Caused by: javax.mail.AuthenticationFailedException: failed to connect
at javax.mail.Service.connect(Service.java:332)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:196)
What is it about?
Well, I already configured META-INF/javamail.providers:
protocol=pop3; type=store; class=com.sun.mail.pop3.POP3Store;
And I have these Maven dependencies in WEB-INF/lib: javax.mail:mail:1.4.4 and com.sun.mail:pop3:1.4.4.
It’s not failing to authenticate, it’s failing to connect. The JavaMail FAQ has tips for debugging connection problems. Note also: