2

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.

Community
  • 1
  • 1
NoNaMe
  • 6,020
  • 30
  • 82
  • 110
  • 1
    Think you use the wron port. You use the smtp port and protocol imap. – Jens Aug 29 '14 at 10:00
  • @Jens Plz see my edited part in question, i have to read message, – NoNaMe Aug 29 '14 at 10:07
  • i do not understand what you will saying? – Jens Aug 29 '14 at 10:09
  • @Jens i mean to say that, i have to read email that is why im using IMAP and SMTP is used to send email. – NoNaMe Aug 29 '14 at 10:12
  • If you want to use IMAP, why are you connecting to the SMTP port? Just remove the port setting from your program and let JavaMail choose the correct port. Also, see this list of [common JavaMail mistakes](http://www.oracle.com/technetwork/java/javamail/faq/index.html#commonmistakes). – Bill Shannon Aug 30 '14 at 02:28

1 Answers1

4

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.

Jensen Buck
  • 566
  • 4
  • 3