Fluent builder for composing a single outbound email and queuing it for delivery, obtained in JS from applications.email.emailBuilder(). A caller sets the recipient (either by address or by profile), the sender details, the subject and body, and optionally one or more attachments, then calls build() to save the composed message as an EmailItem and queue it for sending. The recipient and sender can be resolved automatically from an address if not set explicitly.
Group: Builders
Methods
recipientAddress(String recipientAddress) · recipient(ProfileBean pb) · recipient(Profile profile) · fromAddress(String fromAddress) · replyToAddress(String replyToAddress) · toList(List toList) · ccList(List ccList) · bccList(List bccList) · subject(String subject) · text(String text) · html(String html) · inReplyTo(String inReplyTo) · references(String references) · addAttachement(String fileName, String fileHash, String contentType, String disposition) · addAttachement(String fileName, String fileHash, String contentType) · lead(Lead lead) · build()
recipientAddress(String recipientAddress)
Returns: EmailItemBuilder
Sets the recipient's email address. If no recipient profile is set explicitly, this address is used to look up a matching user or organisation within the account when the email is built.
| Parameter | Description |
|---|---|
recipientAddress | the recipient's email address |
recipient(ProfileBean pb)
Returns: EmailItemBuilder
Sets the recipient directly from a profile bean, unwrapping it to the underlying Profile entity.
| Parameter | Description |
|---|---|
pb | the bean wrapping the recipient's profile |
recipient(Profile profile)
Returns: EmailItemBuilder
Sets the recipient directly from a profile entity.
| Parameter | Description |
|---|---|
profile | the recipient's profile |
fromAddress(String fromAddress)
Returns: EmailItemBuilder
Sets the From address of the email. If not set, and a sender profile has been resolved, the sender's email address is used instead.
| Parameter | Description |
|---|---|
fromAddress | the sending address |
replyToAddress(String replyToAddress)
Returns: EmailItemBuilder
Sets the Reply-To address of the email. If not set, the From address is used instead.
| Parameter | Description |
|---|---|
replyToAddress | the address replies should be sent to |
toList(List toList)
Returns: EmailItemBuilder
Appends one or more To recipients, given as MailboxAddress or String values, to the email's To list. Can be called more than once to add further recipients.
| Parameter | Description |
|---|---|
toList | the recipients to add to the To list |
ccList(List ccList)
Returns: EmailItemBuilder
Appends one or more Cc recipients, given as MailboxAddress or String values, to the email's Cc list. Can be called more than once to add further recipients.
| Parameter | Description |
|---|---|
ccList | the recipients to add to the Cc list |
bccList(List bccList)
Returns: EmailItemBuilder
Appends one or more Bcc recipients, given as MailboxAddress or String values, to the email's Bcc list. Can be called more than once to add further recipients.
| Parameter | Description |
|---|---|
bccList | the recipients to add to the Bcc list |
subject(String subject)
Returns: EmailItemBuilder
Sets the subject line of the email.
| Parameter | Description |
|---|---|
subject | the email subject |
text(String text)
Returns: EmailItemBuilder
Sets the plain text body of the email. If left unset and an HTML body is provided, the plain text body is derived from it automatically when the email is built.
| Parameter | Description |
|---|---|
text | the plain text body |
html(String html)
Returns: EmailItemBuilder
Sets the HTML body of the email. If left unset and a plain text body is provided, the HTML body defaults to that text when the email is built.
| Parameter | Description |
|---|---|
html | the HTML body |
inReplyTo(String inReplyTo)
Returns: EmailItemBuilder
Sets the In-Reply-To header, used to thread this email as a reply to an earlier message.
| Parameter | Description |
|---|---|
inReplyTo | the message id of the email this is in reply to |
references(String references)
Returns: EmailItemBuilder
Sets the References header, used to thread this email within a longer conversation.
| Parameter | Description |
|---|---|
references | the References header value |
addAttachement(String fileName, String fileHash, String contentType, String disposition)
Returns: EmailItemBuilder
Adds an attachment to the email, referencing content already stored in the VFS by its hash.
| Parameter | Description |
|---|---|
fileName | the name of the attached file |
fileHash | the hash used to locate the file's content in the VFS |
contentType | the file's content type |
disposition | the attachment disposition, eg inline or attachment. Defaults to attachment |
addAttachement(String fileName, String fileHash, String contentType)
Returns: EmailItemBuilder
Adds an attachment to the email, referencing content already stored in the VFS by its hash, using the default attachment disposition.
| Parameter | Description |
|---|---|
fileName | the name of the attached file |
fileHash | the hash used to locate the file's content in the VFS |
contentType | the file's content type |
lead(Lead lead)
Returns: EmailItemBuilder
Associates this email with a funnel lead, so its engagement (opens and click-throughs) can be tracked against the lead's EDM history.
| Parameter | Description |
|---|---|
lead | the lead to associate this email with |
build()
Returns: EmailItem
Resolves the recipient and sender if not set explicitly, fills in a missing plain text or HTML body from the other, saves the composed message as an EmailItem, attaches any files added with addAttachement, links it to a lead if one was set, and queues it for sending. Opens and commits its own database session and transaction if none is already active.