Using the SmtpSsl class |
The SmtpSsl class provides an easy to use client interface for securely communicating with SMTP servers using SSL/TLS. The SmtpSsl class provides both implicit and explicit SSL/TLS connections. Implicit SSL/TLS connections are made by default using remote port 465. Explicit SSL/TLS connections are made using an unencrypted connection to port 25 of an SMTP server and then switching to an encrypted mode using the STARTTLS command prior to sending any additional data.
Example
The example below demonstrates connecting using implicit SSL/TLS on port 465
// create new SmtpSsl instance SmtpSsl ssl = new SmtpSsl("smtp.server.com",465);
// establish implicit SSL/TLS connection ssl.connect();
// create email message EmailMessage message = new EmailMessage(); message.setTo("to@domain.com"); message.setFrom("from@domain.com"); message.setSubject("Meeting today at 2:30 p.m."); message.setBody("See you then");
// send message ssl.send(message);
// disconnect ssl.disconnect();
Example
The example below demonstrates connecting using explicit SSL/TLS and STARTTLS command on port 25.
// create new SmtpSsl instance SmtpSsl ssl = new SmtpSsl("smtp.server.com",25);
// set connection type to use STARTTLS command ssl.setConnectionType(SmtpSsl.STARTTLS);
// establish implicit SSL/TLS connection ssl.connect();
// create email message EmailMessage message = new EmailMessage(); message.setTo("to@domain.com"); message.setFrom("from@domain.com"); message.setSubject("Meeting today at 2:30 p.m."); message.setBody("See you then");
// send message ssl.send(message);
// disconnect ssl.disconnect();
|