2
我週末一直在家工作Gmail-Imap-Api。它正在正常工作但是當我回到辦公室並且在這裏嘗試時,它會拋出異常。Gmail Imap - 當我在辦公室網絡時無法連接
Properties props = System.getProperties();
props.put("mail.store.protocol", "imaps");
props.put("mail.smtp.auth", "true");
try {
boolean debug = false;
Authenticator auth = new SMTPAuthenticator(
"***", "***");
Session session = Session.getInstance(props, auth);
session.setDebug(debug);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", "***@gmail.com",
"****");
......
......
這在家庭網絡工作得很好。 現在我想我會添加代理並添加這些代碼行。
System.setProperty("http.proxyHost", "****.com");
System.setProperty("http.proxyPort", "8080");
它仍然不工作,例外是。
com.google.code.javax.mail.MessagingException: imap.gmail.com;
nested exception is:
java.net.UnknownHostException: imap.gmail.com
at com.google.code.com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:665)
at com.google.code.javax.mail.Service.connect(Service.java:295)
at com.google.code.javax.mail.Service.connect(Service.java:176)
at openReports.OpenReportsProject.main(OpenReportsProject.java:43)
Caused by: java.net.UnknownHostException: imap.gmail.com
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:367)
at java.net.Socket.connect(Socket.java:524)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:545)
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
at com.google.code.com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:288)
at com.google.code.com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231)
at com.google.code.com.sun.mail.iap.Protocol.<init>(Protocol.java:113)
at com.google.code.com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:110)
at com.google.code.com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:632)
... 3 more
您必須位於防火牆/代理之後,Gmail-Imap使用的端口(我猜是993)需要在防火牆中打開。 – Santosh
現在該如何解決? 我添加了代理設置ryt?它在這裏不會達到目的嗎? – RaviKiran
剛剛更新了我的評論。 – Santosh