Read the complete article on connecting to IMAP servers using Java: https://blog.aspose.com/2021/07/08/connect-to-an-imap-server-using-java/
Last active
July 9, 2021 05:28
-
-
Save aspose-com-gists/01831893169b346cc3bd4c142c1508b3 to your computer and use it in GitHub Desktop.
Connect to IMAP Servers in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an instance of HttpProxy and specisy host and port | |
HttpProxy proxy = new HttpProxy("18.222.124.59", 8080); | |
// Create IMAP client | |
ImapClient client = new ImapClient("imap.domain.com", "username", "password"); | |
// Set proxy and access the mailbox | |
try { | |
client.setProxy(proxy); | |
client.selectFolder("Inbox"); | |
} finally { | |
if (client != null) | |
client.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Connect and log in to IMAP and set SecurityOptions | |
ImapClient client = new ImapClient("imap.domain.com", "username", "password"); | |
client.setSecurityOptions(SecurityOptions.Auto); | |
String proxyAddress = "192.168.203.142"; // proxy address | |
int proxyPort = 1080; // proxy port | |
SocksProxy proxy = new SocksProxy(proxyAddress, proxyPort, SocksVersion.SocksV5); | |
// Set the proxy | |
client.setProxy(proxy); | |
try { | |
// Access inbox | |
client.selectFolder("Inbox"); | |
} catch (java.lang.RuntimeException ex) { | |
System.out.println(ex.getMessage()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an instance of the ImapClient class | |
ImapClient client = new ImapClient("imap.domain.com", 993, "user@domain.com", "pwd"); | |
// Set the security mode to implicit | |
client.setSecurityOptions(SecurityOptions.SSLImplicit); | |
// Access inbox | |
try { | |
client.selectFolder("Inbox"); | |
} catch (java.lang.RuntimeException ex) { | |
System.out.println(ex.getMessage()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an imapclient with host, username and password | |
ImapClient client = new ImapClient("localhost", "user", "password"); | |
// Access inbox | |
try { | |
client.selectFolder("Inbox"); | |
} catch (java.lang.RuntimeException ex) { | |
System.out.println(ex.getMessage()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment