Error receiving mail through proxy server

we get mail from gmail server.we could connect to the gmail server without a proxy. Since our college has proxy settings, we could not connect to gmailserver even after setting the system properties. we could connect to gmail.com from our browser, but we could not connect to our program.

Properties props = System.getProperties(); props.setProperty("http.proxyHost", "proxyhost"); props.setProperty("http.proxyPort", "proxynumber"); props.setProperty( "mail.imap.socketFactory.class", SSL_FACTORY); props.setProperty( "mail.imap.socketFactory.fallback", "false"); props.setProperty( "mail.imap.port", "993"); props.setProperty( "mail.imap.socketFactory.port", "993"); props.put("mail.imap.host", "imap.gmail.com"); Session session = Session.getDefaultInstance(props, null); store = session.getStore("imap"); store.connect(dialog.getServer(),dialog.getUsername(),dialog.getPassword()); 

get this exception

 java.net.UnknownHostException: imap.gmail.com at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:618) at javax.mail.Service.connect(Service.java:291) at javax.mail.Service.connect(Service.java:172) at EmailClient.connect(EmailClient.java:373) at EmailClient.main(EmailClient.java:475) by: java.net.UnknownHostException: imap.gmail.com at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(Unknown Source) at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(Unknown Source at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:284) at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:201) at com.sun.mail.iap.Protocol.<init>(Protocol.java:109) at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:104) at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:585) 
+4
source share
2 answers

Most likely your proxy uses NTLM authentication, in the past I had problems with Java and NTLM authentication. Not sure if this is really a proxy server that gives you problems.

In any case, instead of directly using the JavaMail API, you can take a look at using the GMail API for Java g4j. It will abstract most of the complexity with gmail in general.

Happy coding!

0
source

JavaMail does not currently support access to mail servers through a web proxy server.

If your proxy server supports the SOCKS V4 or V5 protocol and allows anonymous connections, and you use JDK 1.5 or later and JavaMail 1.4.5 or later, you can configure the SOCKS proxy

0
source

Source: https://habr.com/ru/post/1334498/


All Articles