Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active May 5, 2021 03:27
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/f43b7488e0a05aad6f2a67c221fdc876 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/f43b7488e0a05aad6f2a67c221fdc876 to your computer and use it in GitHub Desktop.
Connect to SMTP Server in Java
// Create an object of HttpProxy
HttpProxy proxy = new HttpProxy("18.222.124.59", 8080);
// Create SMTP client
try (SmtpClient client = new SmtpClient("host", 587, "username", "password")) {
// Set proxy
client.setProxy(proxy);
// Send emails
client.send(new MailMessage("sender@domain.com", "receiver@domain.com", "Sending Email via proxy",
"Implement socks proxy protocol for versions 4, 4a, 5 (only Username/Password authentication)"));
}
// Create an object of SmtpClient
SmtpClient client = new SmtpClient("smtp.domain.com", "username", "password");
// Set security options
client.setSecurityOptions(SecurityOptions.SSLImplicit);
// Proxy settings
String proxyAddress = "192.168.203.142"; // proxy address
int proxyPort = 1080; // proxy port
// Create and set proxy
SocksProxy proxy = new SocksProxy(proxyAddress, proxyPort, SocksVersion.SocksV5);
client.setProxy(proxy);
// Send email
client.send(new MailMessage("sender@domain.com", "receiver@domain.com", "Sending Email via proxy",
"Implement socks proxy protocol for versions 4, 4a, 5 (only Username/Password authentication)"));
// Create an object of SmtpClient
SmtpClient client = new SmtpClient("smtp.gmail.com");
// Set username, password, port, and security options
client.setUsername("your.email@gmail.com");
client.setPassword("your.password");
client.setPort(587);
client.setSecurityOptions(SecurityOptions.SSLExplicit);
// Send emails
client.send(new MailMessage("sender@domain.com", "receiver@domain.com", "Sending Email via proxy", "Test email"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment