Reputation: 311
Javamail works correct in JUnit test and GlassFish 3.1.2, but not works in Tomcat 7.0.41: all "From" headers is NULL! What am I doing wrong? When i run JUnit test with code:
@Test
public void emailTest() {
try {
Properties properties = new Properties();
properties.put("mail.pop3.host", EMAILUtil.POP3_HOST);
properties.put("mail.pop3.disabletop", true);
Store emailStore = Session.getDefaultInstance(properties).getStore(EMAILUtil.STORE_TYPE);
emailStore.connect(EMAILUtil.USER, EMAILUtil.PASSWORD);
Folder emailFolder = emailStore.getFolder(EMAILUtil.DEFAULT_FOLDER);
emailFolder.open(Folder.READ_WRITE);
Message[] messages = emailFolder.getMessages();
System.out.println("Message count: " + messages.length);
int errorCount = 0;
for (int i = 0, n = messages.length; i < n; i++) {
System.out.println("Message: " + messages[i].toString());
System.out.println("From: " + messages[i].getFrom());
}
emailFolder.close(true);
emailStore.close();
} catch (MessagingException ex) {
System.out.println("Readings mails Exception: " + ex.getMessage());
ex.printStackTrace(System.err);
}
}
I get the correct results (same with GlassFish3 results):
Message count: 406
Message: com.sun.mail.pop3.POP3Message@167a
From: [Ljavax.mail.internet.InternetAddress;@f9ead4
Message: com.sun.mail.pop3.POP3Message@72f580
From: [Ljavax.mail.internet.InternetAddress;@153b61e
when i run this code at Tomcat7 I get the following results (all "From" headers is null):
Message count: 406
Message: com.sun.mail.pop3.POP3Message@95acf2
From: null
Message: com.sun.mail.pop3.POP3Message@a38f9f
From: null
can anyone help with this issue? JUnit version: 4.5 Javamail version: 1.4.4 (also i try with 1.5.5 with same result)
Upvotes: 0
Views: 89
Reputation: 29971
Add properties.put("mail.debug", "true"); and compare the debug output in both cases.
Also, try changing Session.getDefaultInstance to Session.getInstance.
Upvotes: 1