Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active July 9, 2021 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/01831893169b346cc3bd4c142c1508b3 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/01831893169b346cc3bd4c142c1508b3 to your computer and use it in GitHub Desktop.
Connect to IMAP Servers in Java
// 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();
}
// 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());
}
// 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());
}
// 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