Java
Chilkat2 Java
Send email using smtp.gmail.com with SSL (port 465).
Send email using smtp.gmail.com with SSL (port 465).Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Email;
import com.chilkatsoft.chilkat2.MailMan;
public class ChilkatExample {
public static void main(String[] args) {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The mailman object is used for sending and receiving email.
MailMan mailman = new MailMan();
// Set the SMTP server.
mailman.setSmtpHost("smtp.gmail.com");
mailman.setSmtpUsername("mySmtpLogin");
mailman.setSmtpPassword("myPassword");
mailman.setSmtpSsl(true);
mailman.setSmtpPort(465);
// Create a new email object
Email email = new Email();
email.setSubject("This is a test");
email.setBody("This is a test");
email.setFrom("Chilkat Support <chilkat.support@gmail.com>");
email.addTo("Chilkat Admin", "admin@chilkatsoft.com");
try {
mailman.sendEmail(email);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
try {
mailman.closeSmtpConnection();
} catch (ChilkatException e) {
System.out.println("Connection to SMTP server not closed cleanly.");
}
System.out.println("Mail Sent!");
}
}