Newer Version Available
Outbound Email
You can use Salesforce to track the status of email in HTML format, including the date the email was sent, first opened and last opened, and the total number of times it was opened.
- SingleEmailMessage
- Instantiates an email object used for sending a single email message. The syntax
is:
- MassEmailMessage
- Instantiates an email object used for sending a mass email message. The syntax
is:
- Messaging
- Includes the static sendEmail method, which sends
the email objects you instantiate with either the SingleEmailMessage or MassEmailMessage
classes, and returns a SendEmailResult object.
The syntax for sending an email is:
where Email is either Messaging.SingleEmailMessage or Messaging.MassEmailMessage.
The optional opt_allOrNone parameter specifies whether sendEmail prevents delivery of all other messages when any of the messages fail due to an error (true), or whether it allows delivery of the messages that don't have errors (false). The default is true.
- Includes the static reserveMassEmailCapacity and
reserveSingleEmailCapacity methods, which can
be called before sending any emails to ensure that the sending organization doesn’t
exceed its daily email limit when the transaction is committed and emails are sent. The
syntax
is:
and
where count indicates the total number of addresses that emails will be sent to.
- The email is not sent until the Apex transaction is committed.
- The email address of the user calling the sendEmail method is inserted in the From Address field of the email header. All email that is returned, bounced, or received out-of-office replies goes to the user calling the method.
- Maximum of 10 sendEmail methods per transaction. Use the Limits methods to verify the number of sendEmail methods in a transaction.
- Single email messages sent with the sendEmail method count against the sending organization's daily single email limit. When this limit is reached, calls to the sendEmail method using SingleEmailMessage are rejected, and the user receives a SINGLE_EMAIL_LIMIT_EXCEEDED error code. However, single emails sent through the application are allowed.
- Mass email messages sent with the sendEmail method count against the sending organization's daily mass email limit. When this limit is reached, calls to the sendEmail method using MassEmailMessage are rejected, and the user receives a MASS_MAIL_LIMIT_EXCEEDED error code.
- Any error returned in the SendEmailResult object indicates that no email was sent.
Messaging.SingleEmailMessage has a method called setOrgWideEmailAddressId. It accepts an object ID to an OrgWideEmailAddress object. If setOrgWideEmailAddressId is passed a valid ID, the OrgWideEmailAddress.DisplayName field is used in the email header, instead of the logged-in user's Display Name. The sending email address in the header is also set to the field defined in OrgWideEmailAddress.Address.
For more information, see Organization-Wide Email Addresses in the Salesforce Help .