public final class MailBuilder extends Object
MailBuilder defines fluent API to build MimeMessage and
if required can send the built message directly.| Constructor and Description |
|---|
MailBuilder(Session session) |
| Modifier and Type | Method and Description |
|---|---|
MailBuilder |
attach(String name,
String link) |
MailBuilder |
attach(String name,
String link,
String cid)
Attach a file referenced by the given link.
|
MailBuilder |
bcc(String... recipients) |
MimeMessage |
build()
Build a new
MimeMessage instance from the provided details. |
MimeMessage |
build(String messageId)
Build a new
MimeMessage instance from the provided details. |
MailBuilder |
cc(String... recipients) |
MailBuilder |
from(String from) |
MailBuilder |
header(String name,
String value) |
MailBuilder |
html(String text) |
MailBuilder |
inline(String name,
String link)
Attach a file as inline content.
|
MailBuilder |
replyTo(String... recipients) |
MimeMessage |
send()
Send the message.
|
MimeMessage |
send(Date date)
Send the message with given send date.
|
MailBuilder |
sender(String sender) |
MailBuilder |
subject(String subject) |
MailBuilder |
text(String text) |
MailBuilder |
to(String... recipients) |
public MailBuilder(Session session)
public MailBuilder subject(String subject)
public MailBuilder to(String... recipients)
public MailBuilder cc(String... recipients)
public MailBuilder bcc(String... recipients)
public MailBuilder replyTo(String... recipients)
public MailBuilder from(String from)
public MailBuilder sender(String sender)
public MailBuilder header(String name, String value)
public MailBuilder text(String text)
public MailBuilder html(String text)
public MailBuilder attach(String name, String link)
public MailBuilder attach(String name, String link, String cid)
If you want to reference the attachment as inline image, provide content id wrapped by angle brackets and refer the image with content id without angle brackets.
For example:
builder.html("<img src='cid:logo.png'>").attach("logo.png", "/path/to/logo.png", "<logo.png>").send();
name - attachment file namelink - attachment file link (url or file path)cid - content idpublic MailBuilder inline(String name, String link)
name - attachment file namelink - attachment file link (url or file path)public MimeMessage build() throws MessagingException, IOException
MimeMessage instance from the provided details.MimeMessageIOException - generally thrown by DataHandlerMessagingException - for failurepublic MimeMessage build(String messageId) throws MessagingException, IOException
MimeMessage instance from the provided details.messageId - custom "Message-ID" to use, null to use auto-generatedMimeMessageIOException - generally thrown by DataHandlerMessagingException - for failurepublic MimeMessage send(Date date) throws MessagingException, IOException
date - send date, can be nullMimeMessageIOException - generally thrown by DataHandlerMessagingException - for failurepublic MimeMessage send() throws MessagingException, IOException
MimeMessageIOException - generally thrown by DataHandlerMessagingException - for failure