Package com.axelor.mail
Class MailBuilder
- java.lang.Object
-
- com.axelor.mail.MailBuilder
-
public final class MailBuilder extends Object
TheMailBuilder
defines fluent API to buildMimeMessage
and if required can send the built message directly.
-
-
Constructor Summary
Constructors Constructor Description MailBuilder(javax.mail.Session session)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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)
javax.mail.internet.MimeMessage
build()
Build a newMimeMessage
instance from the provided details.javax.mail.internet.MimeMessage
build(String messageId)
Build a newMimeMessage
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)
javax.mail.internet.MimeMessage
send()
Send the message.javax.mail.internet.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)
-
-
-
Method Detail
-
subject
public MailBuilder subject(String subject)
-
to
public MailBuilder to(String... recipients)
-
cc
public MailBuilder cc(String... recipients)
-
bcc
public MailBuilder bcc(String... recipients)
-
replyTo
public MailBuilder replyTo(String... recipients)
-
from
public MailBuilder from(String from)
-
sender
public MailBuilder sender(String sender)
-
header
public MailBuilder header(String name, String value)
-
text
public MailBuilder text(String text)
-
html
public MailBuilder html(String text)
-
attach
public MailBuilder attach(String name, String link)
-
attach
public MailBuilder attach(String name, String link, String cid)
Attach a file referenced by the given link.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();
- Parameters:
name
- attachment file namelink
- attachment file link (url or file path)cid
- content id- Returns:
- this
-
inline
public MailBuilder inline(String name, String link)
Attach a file as inline content.- Parameters:
name
- attachment file namelink
- attachment file link (url or file path)- Returns:
- this
-
build
public javax.mail.internet.MimeMessage build() throws javax.mail.MessagingException, IOException
Build a newMimeMessage
instance from the provided details.- Returns:
- an instance of
MimeMessage
- Throws:
IOException
- generally thrown byDataHandler
javax.mail.MessagingException
- for failure
-
build
public javax.mail.internet.MimeMessage build(String messageId) throws javax.mail.MessagingException, IOException
Build a newMimeMessage
instance from the provided details.- Parameters:
messageId
- custom "Message-ID" to use, null to use auto-generated- Returns:
- an instance of
MimeMessage
- Throws:
IOException
- generally thrown byDataHandler
javax.mail.MessagingException
- for failure
-
send
public javax.mail.internet.MimeMessage send(Date date) throws javax.mail.MessagingException, IOException
Send the message with given send date.- Parameters:
date
- send date, can be null- Returns:
- sent
MimeMessage
- Throws:
IOException
- generally thrown byDataHandler
javax.mail.MessagingException
- for failure
-
send
public javax.mail.internet.MimeMessage send() throws javax.mail.MessagingException, IOException
Send the message.- Returns:
- sent
MimeMessage
- Throws:
IOException
- generally thrown byDataHandler
javax.mail.MessagingException
- for failure
-
-