public interface SmtpClient
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.
Modifier and Type | Method and Description |
---|---|
javax.mail.Session |
createSession()
Create a session object that is pre-populated with the connection related parameters.
|
Future<Void> |
send(javax.mail.Message message)
Send the message.
|
javax.mail.Session createSession()
Future<Void> send(javax.mail.Message message) throws javax.mail.MessagingException
javax.mail.MessagingException
javax.mail.Transport.send(Message)
This work is licensed under a Creative Commons Attribution 4.0 International License.