Package org.codice.ddf.platform.email
Interface SmtpClient
public interface SmtpClient
Provides a light-weight interface to javax.mail. The user should call
createSession() to
get a session that is preconfigured with the hostname and port number of the email server. Next,
construct a Message and submit it to send(Message).
Example:
SmtpClient smtpClient = <get an instance>
Session session = emailService.createSession();
MimeMessage mimeMessage = new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress("from@test.com"));
mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress("to@test.com"));
mimeMessage.setSubject("The Subject Line");
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("The Body Text");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
mimeMessage.setContent(multipart);
emailService.send(mimeMessage);
This code is experimental. While this interface is functional and tested, it may change or be removed in a future version of the library.
-
Method Summary
Modifier and TypeMethodDescriptionjavax.mail.SessionCreate a session object that is pre-populated with the connection related parameters.send(javax.mail.Message message) Send the message.
-
Method Details
-
createSession
javax.mail.Session createSession()Create a session object that is pre-populated with the connection related parameters.- Returns:
- session object
-
send
Send the message. May be sent synchronously or asynchronously.- Returns:
- a future that the caller can use to determine when the operation completes
-