Reading emails using IMAP in java
<p>I am trying to read emails from my inbox using IMAP in java but I am getting java.net.UnknownHostException . iS it something related to proxy or firewall? As I am doing such a program for the first time , I am confused. Please help. Thank you in advance.</p>

<p>public class mailRead {</p>

<pre><code>   public static void check(String host, String storeType, String user, String password) 
   {
      try {

          Properties props = new Properties();

        props.setProperty("mail.store.protocol", "imaps");
            Session session = Session.getInstance(props, null);
            Store store = session.getStore("imaps");

            System.out.println("emailsession done !!");


            store.connect("2e1211jk-1178@external.pk.com", "raj21@pk.com", "kkk111KKK");


          //create the folder object and open it
          Folder emailFolder = store.getFolder("INBOX");
          emailFolder.open(Folder.READ_ONLY);

          Folder inbox = store.getFolder("INBOX");
            inbox.open(Folder.READ_ONLY);

            Message msg = inbox.getMessage(inbox.getMessageCount());
            Address[] in = msg.getFrom();

            for (Address address : in) {
                System.out.println("FROM:" + address.toString());
            }



      store.close();

      } catch (NoSuchProviderException e) {
         e.printStackTrace();
      } catch (MessagingException e) {
         e.printStackTrace();
      } catch (Exception e) {
         e.printStackTrace();
      }
   }

   public static void main(String[] args) {

      String host = "2e1211jk-1178@external.pk.com";// change accordingly
      String mailStoreType = "IMAP";
      String username = "raj21@pk.com";// change accordingly
      String password = "kkk111KKK";// change accordingly

      check(host, mailStoreType, username, password);

   }
</code></pre>

<p>}</p>