I am facing the following Exception:
javax.mail.MessagingException: 220 cnsmail.company.local Microsoft ESMTP MAIL Service ready at Fri, 29 Aug 2014 05:42:13 -0400;
nested exception is:
com.sun.mail.iap.ConnectionException: 220 cnsmail.company.local Microsoft ESMTP MAIL Service ready at Fri, 29 Aug 2014 05:42:13 -0400
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:569)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
at com.cinnova.Email.MailReader.<init>(MailReader.java:59)
at com.cinnova.Email.MailReader.main(MailReader.java:30)
Caused by: com.sun.mail.iap.ConnectionException: 220 cnsmail.company.local Microsoft ESMTP MAIL Service ready at Fri, 29 Aug 2014 05:42:13 -0400
at com.sun.mail.imap.protocol.IMAPProtocol.processGreeting(IMAPProtocol.java:230)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:114)
at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:104)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:538)
... 4 more
Here is my code using which I am trying to connect to mail server to read mails using Java.
Properties props = new Properties();
props.put("mail.imap.port", "25");
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imap");
store.connect(ServerIP, "cma", "C0rnh0le$8");
When system tries to compile the line store.connect(ServerIP, "cma", "C0rnh0le$8");
it generates the above mentioned exception, I found
this and this on StackOverflow, but not get any help after adding that jar.
Define Protocol
SMTP - is the protocol to send email
POP3 - is the protocol to receive emails
IMAP- IMAP is an acronym for Internet Message Access Protocol. Its an advanced protocol for receiving messages.
The default IMAP port is 143. You are using the default SMTP port, 25. That should fix your problem, assuming the host/username/password are correct!
Cheers, and happy coding.