Read Gmail mails with IMAP protocol behind proxy,firewall with PAC

2.1k views Asked by At

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)
2

There are 2 answers

3
Caadi0 On

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>");
0
Bill Shannon On

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.