FTPClient
FTPFileInfo
HTTPClient
HTTPClientLoggingConfig
HTTPRequestPart
Mail
SFTPClient
SFTPFileInfo
WebDAVClient
WebDAVFileInfo
DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!
Let us know so we can improve!
This class is used to send an email with either plain text or MimeEncodedText content. Recipient data (from, to, cc, bcc) and subject are specified using setter methods. When the send() method is invoked, the email is put into an internal queue and sent asynchronously.
Note: when this class is used with sensitive data, be careful in persisting sensitive information to disk.
The following example script sends an email with MimeEncodedText content:
1function sendMail() {
2 var template: Template = new dw.util.Template("myTemplate.isml");
3
4 var o: Map = new dw.util.HashMap();
5 o.put("customer","customer");
6 o.put("product","product");
7
8 var content: MimeEncodedText = template.render(o);
9 var mail: Mail = new dw.net.Mail();
10 mail.addTo("to@example.org");
11 mail.setFrom("from@example.org");
12 mail.setSubject("Example Email");
13 mail.setContent(content);
14
15 mail.send();//returns either Status.ERROR or Status.OK, mail might not be sent yet, when this method returns
16 }See Sending email via scripts or hooks in the documentation for additional examples.
| Property | Description |
|---|---|
| bcc: List | Gets the bcc address List. |
| cc: List | Gets the cc address List. |
| from: String | Gets the email address to use as the from address for the email. |
replyTo: List (read-only) | Gets the replyTo address List. |
| subject: String | Gets the subject of the email. |
| to: List | Gets the to address List where the email is sent. |
| Constructor | Description |
|---|---|
| Mail() |
| Method | Description |
|---|---|
| addAttachment(File) | Adds a file attachment to the email. |
| addBcc(String) | Adds an address to the bcc List. |
| addCc(String) | Adds an address to the cc List. |
| addReplyTo(String) | Adds an address to the replyTo List. |
| addTo(String) | Adds an address to the to address List. |
| getBcc() | Gets the bcc address List. |
| getCc() | Gets the cc address List. |
| getFrom() | Gets the email address to use as the from address for the email. |
| getReplyTo() | Gets the replyTo address List. |
| getSubject() | Gets the subject of the email. |
| getTo() | Gets the to address List where the email is sent. |
| send() | prepares an email that is queued to the internal mail system for delivery. |
| setBcc(List) | Sets the bcc address List. |
| setCc(List) | Sets the cc address List where the email is sent. |
| setContent(MimeEncodedText) | Mandatory Uses MimeEncodedText to set the content, MIME type and encoding. |
| setContent(String) | Mandatory Sets the email content. |
| setContent(String, String, String) | Mandatory Sets the email content, MIME type, and encoding. |
| setFrom(String) | Mandatory Sets the sender address for this email. |
| setListUnsubscribe(String) | Sets the List-Unsubscribe header value to work with List-Unsubscribe-Post to allow integration with an externally-managed mailing list. |
| setListUnsubscribePost(String) | Sets the List-Unsubscribe-Post header value. |
| setSubject(String) | Mandatory sets the subject for the email. |
| setTo(List) | Sets the to address List where the email is sent. |
| static validateAddress(String) | Validates the address that is sent as parameter. |
assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values
Gets the bcc address List.
Gets the cc address List.
Gets the email address to use as the from address for the
email.
(read-only)Gets the replyTo address List.
Gets the subject of the email.
Gets the to address List where the email is sent.
Adds a file attachment to the email. This method is restricted to Job context only.
Parameters:
Returns:
Throws:
Adds an address to the bcc List. Address must conform to the RFC822 standard.
Parameters:
bcc address List.Returns:
Adds an address to the cc List. The address must conform to RFC822 standard.
Parameters:
cc address List.Returns:
Adds an address to the replyTo List. Address must conform to the RFC822 standard.
Parameters:
replyTo address List.Returns:
Throws:
Adds an address to the to address List. The address must conform to the RFC822 standard.
Parameters:
to address List.Returns:
Gets the bcc address List.
Returns:
bcc address List or empty List if no bcc
addresses are set.Gets the cc address List.
Returns:
cc address List or empty List if no cc
addresses are set.Gets the email address to use as the from address for the
email.
Returns:
from address for this mail or null if no from
address is set yet.Gets the replyTo address List.
Returns:
replyTo address List or empty List if no replyTo
addresses are set.Gets the subject of the email.
Returns:
subject or null if no subject is set yet.Gets the to address List where the email is sent.
Returns:
to address List or empty List if no to
addresses are set.prepares an email that is queued to the internal mail system for delivery.
Returns:
from,
content, and subject are
empty an IllegalArgumentException is raised. An
IllegalArgumentException is raised if neither to, cc
nor bcc are set.Sets the bcc address List. If there
are already bcc addresses they are overwritten.
Parameters:
Returns:
Sets the cc address List where the email is sent. If there are
already cc addresses set, they are overwritten. The address(es) must
conform to the RFC822 standard.
Parameters:
Returns:
Mandatory Uses MimeEncodedText to set the content, MIME type and encoding.
Parameters:
Returns:
Mandatory Sets the email content. The MIME type is set to "text/plain;charset=UTF-8" and encoding set to "UTF-8".
Parameters:
Returns:
Mandatory Sets the email content, MIME type, and encoding. No validation of MIME type and encoding is done. It is the responsibility of the caller to specify a valid MIME type and encoding.
Parameters:
Returns:
Mandatory Sets the sender address for this email. The address must conform to the RFC822 standard.
Parameters:
Returns:
Sets the List-Unsubscribe header value to work with List-Unsubscribe-Post to allow integration with an externally-managed mailing list.
Parameters:
Returns:
Sets the List-Unsubscribe-Post header value. This header supports one-click unsubscribe functionality.
Parameters:
Returns:
Mandatory sets the subject for the email. If the subject is not set
or set to null at the time send() is invoked and
IllegalArgumentException is thrown.
Parameters:
subject of the mail to send.Returns:
Sets the to address List where the email is sent. If there are
already to addresses, they are overwritten.
Parameters:
Returns:
Validates the address that is sent as parameter. This validation includes:
Parameters:
Returns: