Why is showing below error message while reading email from outlook using Java Mail API?

56 views
Skip to first unread message

Poovaraj Thangamariappan

unread,
Aug 6, 2017, 3:13:51 AM8/6/17
to seleniu...@googlegroups.com
Hi Team

I am working selenium automation testing using java language. I have to do email validation functionality using java mail API. I am getting below error message while connection email server. Please find the source code and error message. Could you help me how to resolve this issue ? 
Thanks in Advance !

Code :-

Why is showing below error message while reading email from outlook?

Code

public class EmailValidation

{

      public static void main(String[] args)

      {

 

            String host = "11.1.210.133";// change accordingly        

            String mailStoreType = "pop3";

            String username = "Email";// change accordingly

            String password = "test";// change accordingly

 

            check(host, mailStoreType, username, password);

 

         }

            public static void check(String host, String storeType, String user,

                  String password)

               {

                  try {

 

                  //create properties field

                  Properties properties = new Properties();

                  properties.put("mail.pop3.host", host);

                  properties.put("mail.pop3.port", "995");             

                  properties.put("mail.pop3.starttls.enable", "true");

                  Session emailSession = Session.getDefaultInstance(properties);

             

                  //create the POP3 store object and connect with the pop server

                  emailSession.setDebug(true);

                  Store store = emailSession.getStore("pop3s");

 

                  store.connect(host, user, password);

 

                  //create the folder object and open it

                  Folder emailFolder = store.getFolder("INBOX");

                  emailFolder.open(Folder.READ_ONLY);

 

                  // retrieve the messages from the folder in an array and print it

                  Message[] messages = emailFolder.getMessages();

                  System.out.println("messages.length---" + messages.length);

 

                  for (int i = 0, n = messages.length; i < n; i++) {

                     Message message = messages[i];

                     System.out.println("---------------------------------");

                     System.out.println("Email Number " + (i + 1));

                     System.out.println("Subject: " + message.getSubject());

                     System.out.println("From: " + message.getFrom()[0]);

                     System.out.println("Text: " + message.getContent().toString());

 

                  }

 

                  //close the store and folder objects

                  emailFolder.close(false);

                  store.close();

 

                  } catch (NoSuchProviderException e) {

                     e.printStackTrace();

                  } catch (MessagingException e) {

                     e.printStackTrace();

                  } catch (Exception e) {

                     e.printStackTrace();

                  }

               } 

 

}

 

 

Error Message :-

 

DEBUG: setDebug: JavaMail version 1.4ea

DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc]

DEBUG POP3: connecting to host "11.1.210.133", port 995, isSSL true

javax.mail.MessagingException: Connect failed;

  nested exception is:

      java.net.ConnectException: Connection timed out: connect

      at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:148)

      at javax.mail.Service.connect(Service.java:275)

      at javax.mail.Service.connect(Service.java:156)

      at EmailValidation.check(EmailValidation.java:48)

      at EmailValidation.main(EmailValidation.java:29)

Caused by: java.net.ConnectException: Connection timed out: connect

      at java.net.DualStackPlainSocketImpl.connect0(Native Method)

      at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)

      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)

      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)

      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)

      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)

      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)

      at java.net.Socket.connect(Socket.java:589)

      at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)

      at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)

      at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)

      at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)

      at com.sun.mail.pop3.Protocol.<init>(Protocol.java:81)

      at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:201)

      at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:144)

      ... 4 more

 



Regards,
Poovaraj

Krishnan Mahadevan

unread,
Aug 6, 2017, 11:53:55 AM8/6/17
to seleniu...@googlegroups.com

Please help keep this forum relevant by posting queries that are related to Selenium/WebDriver.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAMu9-ZXO1Ek%2Bjhc3KfS%2BXb8HQ5zfgv7mBVMkfMUGvGXWr59wiA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Poovaraj Thangamariappan

unread,
Aug 7, 2017, 1:15:21 PM8/7/17
to seleniu...@googlegroups.com
Hi,

Sure, I will post only selenium related queries in future. I am working in selenium automation and I want to develop script for email notifications.  I have faced some issues when I am developing this script, so I have posted this query here !

Thanks & Regards
Poovaraj

Sent from BlueMail

Bharadwaj Pendyala

unread,
Aug 7, 2017, 10:30:11 PM8/7/17
to Selenium Users
I have recently automated sending Emails through the Java mail API, Although there are different protocols for sending and receiving according to the error log I would suggest you go through you the hostname and other email related settings which would resolve the error.
Reply all
Reply to author
Forward
0 new messages