Email Class (Base Email Methods)
Contains base email methods common to both single and mass email.
Sending an email by using Apex requires domain-level and user-level email verification. System-generated emails also require verification of the From email address. Email delivery fails if any of these verifications is incomplete. See Requirements to Send Email from Salesforce.
If templates are not being used, all email content must be in plain text, HTML, or both.Visualforce email templates cannot be used for mass email.
The following are methods for Email. All are instance methods.
-
Indicates whether the email sender receives a copy of the email that is sent. For a mass mail, the sender is only copied on the first email sent.
-
Optional. The email address that receives the message when a recipient replies.
-
The ID of the template to be merged to create this email. Specify a value for
setTemplateId,setHtmlBody, orsetPlainTextBody. Or, you can define bothsetHtmlBodyandsetPlainTextBody. -
setSaveAsActivity(saveAsActivity)
Optional. The default value is
true, meaning the email is saved as an activity. This argument only applies if the recipient list is based ontargetObjectIdortargetObjectIds. If HTML email tracking is enabled for the organization, you will be able to track open rates. -
setSenderDisplayName(displayName)
Optional. The name that appears on the From line of the email. This cannot be set if the object associated with a
setOrgWideEmailAddressIdfor a SingleEmailMessage has defined itsDisplayNamefield. -
Indicates whether the email includes an email signature if the user has one configured. The default is
true, meaning if the user has a signature it is included in the email unless you specifyfalse.
Indicates whether the email sender receives a copy of the email that is sent. For a mass mail, the sender is only copied on the first email sent.
public Void setBccSender(Boolean bcc)
-
bcc:
Type: Boolean
Type: Void
If the BCC compliance option is set at the organization level, the user cannot add BCC addresses on standard messages. The following error code is returned: BCC_NOT_ALLOWED_IF_BCC_ COMPLIANCE_ENABLED. Contact your Salesforce representative for information on BCC compliance.
Optional. The email address that receives the message when a recipient replies.
public Void setReplyTo(String replyAddress)
-
replyAddress:
Type: String
Type: Void
The ID of the template to be merged to create this email. Specify a value for setTemplateId, setHtmlBody, or setPlainTextBody. Or, you can define both setHtmlBody and setPlainTextBody.
public Void setTemplateID(ID templateId)
-
templateId:
Type: ID
Type: Void
setHtmlBody and setPlainTextBody apply only to single email methods, not to mass email methods.
Optional. The default value is true, meaning the email is saved as an activity. This argument only applies if the recipient list is based on targetObjectId or targetObjectIds. If HTML email tracking is enabled for the organization, you will be able to track open rates.
public Void setSaveAsActivity(Boolean saveAsActivity)
-
saveAsActivity:
Type: Boolean
Type: Void
Optional. The name that appears on the From line of the email. This cannot be set if the object associated with a setOrgWideEmailAddressId for a SingleEmailMessage has defined its DisplayName field.
public Void setSenderDisplayName(String displayName)
-
displayName:
Type: String
Type: Void
Indicates whether the email includes an email signature if the user has one configured. The default is true, meaning if the user has a signature it is included in the email unless you specify false.
public Void setUseSignature(Boolean useSignature)
-
useSignature:
Type: Boolean
Type: Void