0

I have PAC file and proxy port with me but not able to login and readGMail mails. Can anyone show me how to use PAC and proxy port in JAVAMAIL API .I have done setting like

    propsIMAP = new Properties();
    propsSMTP = new Properties();

    propsIMAP.setProperty("http.proxyHost", "http-proxy01.domain.com");   
    propsIMAP.setProperty("http.proxyPort", "88");
    propsIMAP.put("mail.imap.starttls.enable","true");
    propsIMAP.put("mail.imap.host", ImapServerName);
    propsIMAP.put("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    propsIMAP.put("mail.imap.socketFactory.fallback", "false");
    propsIMAP.put("mail.transport.protocol", "imaps");
    propsIMAP.put("mail.imap.auth", "true");
    propsIMAP.put("mail.imaps.port", "993");

and getting error as :

      DEBUG IMAP: mail.imap.fetchsize: 16384
DEBUG IMAP: mail.imap.ignorebodystructuresize: false
  DEBUG IMAP: mail.imap.statuscachetimeout: 1000
  DEBUG IMAP: mail.imap.appendbuffersize: -1
  DEBUG IMAP: mail.imap.minidletime: 10
   DEBUG IMAP: enable STARTTLS
    DEBUG IMAP: trying to connect to host "webmail.gmail.com", port 993, isSSL false
  javax.mail.MessagingException: webmail.gmail.com;
   nested exception is:
   java.net.UnknownHostException: webmail.gmail.com
      at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:670)
javadev
  • 69
  • 1
  • 1
  • 7

2 Answers2

1

The problem here is that you are trying to connect to a host that simply doesn't exist. Correct settings for gmail are :-

props.setProperty("mail.imap.host", "imap.gmail.com");
props.setProperty("mail.imap.port", "993"); 

You can use the following :-

  Properties props = System.getProperties();
  props.setProperty("mail.store.protocol", "imaps");
  // Put all other Properties here
  Session session = Session.getDefaultInstance(props, null);
  Store store = session.getStore("imaps");
  store.connect("imap.gmail.com", "<username>@gmail.com", "<password>");
Caadi0
  • 504
  • 8
  • 23
  • @user3009301 : If the code works, could you accept the answer and mark the question answered. If it still doesn't work leave a comment. – Caadi0 Dec 17 '13 at 11:12
  • Exception in thread "main" java.lang.SecurityException: Access to default session denied – javadev Dec 17 '13 at 12:39
  • @user3009301 : I think you need a authenticator, see this SO question http://stackoverflow.com/questions/11566772/java-mail-api-exception-thrown-saying-java-lang-securityexception-access-to-d – Caadi0 Dec 17 '13 at 13:16
0

It looks like you're just making stuff up in those property settings. See these JavaMail FAQ entries:

Bottom line, you need more than a web proxy server, and PAC files are never going to work.

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40