Newer Version Available

This content describes an older version of this product. View Latest

EmailTemplate

Represents a template for an email, mass email, list email, or Sales Engagement email. Supported in first-generation managed packages only.

This type extends the MetadataWithContent metadata type and inherits its content and fullName fields.

First-generation packaging only is supported for Lightning email templates.

Note

File Suffix and Directory Location

The file suffix is .email for the template file. The accompanying metadata file is named EmailTemplateName-meta.xml.

EmailTemplate components are stored in the email folder in the corresponding package directory. For example, for an email template named SampleTemplate in the sampleFolder folder, there’s a SampleTemplate-meta.xml in the email/sampleFolder of the package.

Retrieving Email Templates

You can’t use the wildcard (*) symbol with email templates in package.xml. To retrieve the list of email templates for populating package.xml with explicit names, call listMetadata() and pass in EmailTemplate as the type.

The following example shows folders in package.xml:

1<?xml version="1.0" encoding="UTF-8"?>
2<Package xmlns="http://soap.sforce.com/2006/04/metadata">
3    <types>
4        <members>MyDBFolder/MyDBName</members>
5        <name>Dashboard</name>
6    </types>
7    <types>
8        <members>MyDocumentFolder/MyDocumentName</members>
9        <name>Document</name>
10    </types>
11    <types>
12        <members>unfiled$public/MarketingProductInquiryResponse</members>
13        <members>unfiled$public/SalesNewCustomerEmail</members>
14        <name>EmailTemplate</name>
15    </types>
16    <types>
17        <members>MyReportFolder/MyReportName</members>
18        <name>Report</name>
19    </types>
20    <version>66.0</version>
21</Package>

Version

Email templates are available in API version 12.0 and later.

Fields

This metadata type contains the following fields:

Field Name Field Type Description
apiVersion double The API version if it's a Visualforce email template. Every Visualforce email template has an API version specified at creation. This field is available in API version 16.0 and later.
attachedDocuments string[] A list of references to documents in your organization. These documents are included as attachments in the email template. Each document is referenced by its path, for example MyFolder/MyDocument.txt.
attachments Attachment[] A list of attachments for the email template.
available boolean Required. Indicates whether this template is offered to users when sending an email (true) or not (false).
content base64Binary Content of the email template. Base 64-encoded binary data. Before making an API call, client applications must encode the binary attachment data as base64. Upon receiving a response, client applications must decode the base64 data to binary. This conversion is handled for you by a SOAP client. This field contains:
  • Binary content of the email body if type is set to text
  • HTML email content if type is set to html
  • HTML body if type is set to custom
  • Visualforce body if type is set to visualforce

This field is inherited from the MetadataWithContent component.

description string The email template description describes the reason for creating the template.
encodingKey Encoding (enumeration of type string) Required for Classic email templates. The default encoding setting is Unicode: UTF-8. Change it if your template requires data in a different format.

Valid values include:

  • UTF-8—Unicode (UTF-8)
  • ISO-8859-1—General US & Western Europe (ISO-8859–1, ISO-LATIN-1)
  • Shift_JIS—Japanese (Shift-JIS)
  • ISO-2022-JP—Japanese (JIS)
  • EUC-JP—Japanese (EUC-JP)
  • x-SJIS_0213—Japanese (Shift-JIS_2004)
  • ks_c_5601-1987—Korean (ks_c_5601-1987)
  • Big5—Traditional Chinese (Big5)
  • GB2312—Simplified Chinese (GB2312)
  • Big5-HKSCS—Traditional Chinese Hong Kong (Big5–HKSCS)

Lightning email templates don’t use this field. Instead, the encoding values are taken directly from the user’s encoding settings.

fullName string The email template developer name used as a unique identifier for API access. The fullName can contain only underscores and alphanumeric characters. It must be unique, begin with a letter, not include spaces, not end with an underscore, and not contain two consecutive underscores. If this field contained characters before version 14.0 that are no longer allowed, the characters were stripped out of this field, and the previous value of the field was saved in the name field. This field is inherited from the Metadata component.
letterhead string The letterhead name associated with this email template. Only available when type is set to html.
name string Required. Email template name. The list of characters allowed in the fullName field has been reduced for versions 14.0 and later. This field contains the value contained in the fullName field before version 14.0.
packageVersions PackageVersion[] The list of package versions for any managed packages containing components that are referenced by this email template. This field is only relevant for Visualforce email templates.

For more information about managed packages, see Second-Generation Managed Packages in the Salesforce DX Developer Guide. This field is available in API version 16.0 and later.

relatedEntityType Object Name (enumeration of type string) Reserved for future use with Lightning Experience.
style EmailTemplateStyle (enumeration of type string) Required. The style of the template. This field is only available when type is set to html.

Valid style values include:

  • none
  • freeForm
  • formalLetter
  • promotionRight
  • promotionLeft
  • newsletter
  • products
subject string The email subject.

The limit is 1,000 characters for Lightning email templates and 230 characters for Classic email templates.

textOnly string The text of the email body if type is set to html or custom.
type EmailTemplateType (enumeration of type string) Required. The email template type.

The valid values are:

  • text - all users can create or change text email templates.
  • html - administrators and users with the “Edit HTML Templates” permission can create HTML email templates based on a letterhead.
  • custom - administrators and users with the “Edit HTML Templates” permission can create custom HTML email templates without using a letterhead. You must either know HTML or obtain the HTML code to insert in your email template.
  • visualforce - administrators and users with the Customize Application permission can create email templates using Visualforce.
UiType EmailTemplateUiType (enumeration of type string) Indicates the user interface where this template is usable. Valid values are:
  • Aloha (Salesforce Classic)
  • SFX (Lightning Experience)
  • SFX_Sample (Lightning Experience Sample)

If UiType is SFX, the type must be custom.

Packaging is supported for Salesforce Classic email templates only.

Example

1<EmailTemplate>
2    <available>true</available>
3    <description>Notification that user has been added to a community.</description>
4    <encodingKey>UTF-8</encodingKey>
5    <name>Communities: New Member Welcome Email</name>
6    <style>none</style>
7    <subject>Welcome to {!Community_Name}</subject>
8    <type>custom</type>
9    <uiType>Aloha</uiType>
10</EmailTemplate>

Attachment

Attachment represents an email attachment.

Field Field Type Description
content base64Binary Required. The attachment content. Base 64-encoded binary data. Before making an API call, client applications must encode the binary attachment data as base64. Upon receiving a response, client applications must decode the base64 data to binary. This conversion is handled for you by a SOAP client.
name string Required. The attachment file name.

Declarative Metadata Sample Definition

Here's a sample XML definition of an email template.

1<?xml version="1.0" encoding="UTF-8"?>
2<EmailTemplate xmlns="http://soap.sforce.com/2006/04/metadata">
3    <available>true</available>
4    <description>Sample Email Template</description>
5    <encodingKey>ISO-8859-1</encodingKey>
6    <name>Sample Email Template</name>
7    <style>none</style>
8    <subject>Sample email subject</subject>
9    <textOnly>Your case has been resolved.</textOnly>
10    <type>custom</type>
11</EmailTemplate>

Wildcard Support in the Manifest File

This metadata type doesn’t support the wildcard character * (asterisk) in the package.xml manifest file. For information about using the manifest file, see Deploying and Retrieving Metadata with the Zip File.