EmailTemplate defines reusable message content for individual email, mass email, list email, and Sales Engagement email. It supplies the subject and body, not the rules that decide when to send the message. Templates can also serve workflow alerts, approval processes, routing rules, and Network or Portal communications.
A template is more than its descriptive metadata. EmailTemplate extends MetadataWithContent, so a complete asset includes both the body content and its accompanying metadata. Merge expressions, Visualforce rendering logic, and some dependencies appear in the body rather than in ordinary metadata reference elements.
Key Elements
| Element | What the Element Controls |
|---|---|
fullName, name
|
fullName identifies the template by its developer name for API access. name is the required template name. Retrieval requires the folder-qualified API identity, not a display name or record ID. |
available |
Required Boolean. Determines whether users are offered the template when sending email. It does not establish actual usage or activate referring business processes. |
type |
Required. Values are text, html, custom, and visualforce. This determines the body format and the applicable authoring permissions. |
uiType |
Identifies the usable interface: Aloha for Salesforce Classic, SFX for Lightning Experience, or SFX_Sample for Lightning Experience Sample. SFX requires type=custom. |
content |
Inherited body content: text, letterhead-based HTML, custom HTML, or Visualforce according to type. Base64 encoding applies to API transport, not to how the body file must be written. |
textOnly |
The plain-text body accompanying an html or custom template's HTML content. |
subject |
The email subject. The limit is 230 characters for Classic templates and 1,000 characters for Lightning templates. |
encodingKey |
Required for Classic templates, with a default of UTF-8. Other supported values include ISO-8859-1, Shift_JIS, ISO-2022-JP, EUC-JP, x-SJIS_0213, ks_c_5601-1987, Big5, GB2312, and Big5-HKSCS. Lightning templates use the user's encoding settings instead. |
letterhead |
References the letterhead used by a type=html template. It does not apply to custom HTML templates. |
style |
Required for type=html. Values are none, freeForm, formalLetter, promotionRight, promotionLeft, newsletter, and products. |
attachedDocuments |
References external Document components included as email attachments. Each reference is a document path, such as MyFolder/MyDocument.txt. |
attachments |
Contains embedded attachment entries. Each entry requires name and content; attachment content is base64-encoded for API transport. |
apiVersion |
Records a Visualforce template's API version, specified when the template is created. |
packageVersions |
For Visualforce templates only, identifies managed-package versions containing components referenced by the template. It does not determine the template's own packaging eligibility. |
relatedEntityType |
Has a recognized association with CustomObject, but its documented behavior is reserved for future use with Lightning Experience. It is not an authoritative inventory of objects used in merge expressions. |
Behavior and Constraints
Interpret type and uiType together. type=custom means HTML without a letterhead; it does not, by itself, identify a Lightning template. A template with uiType=SFX must have type=custom.
-
textsupplies a text body. At the documented type-level authoring scope, all users can create or change text templates. -
htmlsupplies HTML based on aLetterhead. Bothletterheadand the requiredstylesetting apply to this type. -
customsupplies HTML without a letterhead. Creating eitherhtmlorcustomtemplates requires an administrator or a user with the "Edit HTML Templates" permission. -
visualforcesupplies a Visualforce body. Creation requires an administrator or a user with "Customize Application".
available=true makes the template available for selection when users send email. It is not evidence that the template is used, and it does not activate workflow alerts, approval processes, or other configurations that reference it. Likewise, available=false is not proof that a template has no dependencies.
The two attachment mechanisms have different deployment implications. attachedDocuments points to separate Document components. By contrast, attachments holds embedded attachment data inside the template structure. The supporting Attachment structure is not a separate deployable EmailTemplate component.
For API calls, body and attachment binary data are base64-encoded before transmission and decoded on receipt; a SOAP client handles this conversion. This transport requirement does not mean that the template's body file must contain base64 text.
Visualforce recipient and related-record declarations belong in the template markup. recipientType and relatedToType are markup attributes, not additional top-level EmailTemplate metadata elements. Expressions can use recipient and relatedTo, so missing merged values require examination of both the markup and the sending context.
Deployment and Retrieval
The template body uses the .email suffix. Components reside under the package's email directory, organized by folder, with accompanying metadata. For example, a template in sampleFolder resides under email/sampleFolder. Retrieve and inspect both parts: the descriptive metadata alone can omit the expressions and rendering logic that explain a dependency or merge problem.
EmailTemplate does not support * in package.xml. Call listMetadata() with EmailTemplate as the type, then populate the manifest with explicit component names. The Metadata API reference documents this retrieval requirement.
Use FolderDeveloperName/TemplateDeveloperName for each template member. For example, unfiled$public/SalesNewCustomerEmail identifies a template in the unfiled public folder. Neither the folder's display label, the template's display name, nor a runtime record ID substitutes for this folder-qualified retrieval key.
The template developer name must be unique, begin with a letter, and contain only alphanumeric characters and underscores. It cannot contain spaces, end with an underscore, or contain two consecutive underscores. These developer-name rules do not remove the folder qualification required in a manifest member.
A correct Folder/Template path does not establish that the destination folder exists. In reported Ant deployments, resolving a missing-folder failure required including the folder metadata and listing the folder itself as a separate member under EmailTemplate, alongside the template members. This is reported deployment guidance, not a promise that deploying a template automatically creates its folder.
For replacement or deletion analysis, inspect the configurations that actually reference the template and the references embedded in its body. Possible relationships alone do not establish actual use. A template used by an approval process, workflow alert, or account-access notification has a wider impact than a template used only in the email composer.
packageVersions describes versions of referenced managed-package components for Visualforce rendering. It neither establishes eligibility for a packaging model nor resolves the conflicting Lightning packaging statements described below.
Relationships
Outgoing dependencies include documents, letterheads, and references embedded in body expressions. The relationship label filedata identifies body-content references; these need not appear as ordinary reference elements in the accompanying metadata. Incoming references can make a template a shared communication dependency. Network and Portal references cover welcome, registration, comments, ownership notifications, password recovery, verification, device activation, and other account-access messages.
References
-
CustomField:filedata. -
CustomLabel:filedata. -
CustomObject:filedata,relatedEntityType. The latter is documented as reserved for future use and does not fully describe merge-expression dependencies. -
Document:attachedDocuments. -
Letterhead:letterhead.
Referenced By
-
ApprovalProcess:emailTemplate,postTemplate. -
AssignmentRules:assignedToTemplate,notifyToTemplate,template. -
AssignmentRule:assignedToTemplate,notifyToTemplate,template. -
AutoResponseRules:assignedToTemplate,notifyToTemplate,template. -
AutoResponseRule:assignedToTemplate,notifyToTemplate,template. -
EscalationRules:assignedToTemplate,notifyToTemplate,template. -
EscalationRule:assignedToTemplate,notifyToTemplate,template. -
Network:caseCommentEmailTemplate,changePasswordTemplate,chgEmailVerNewTemplate,chgEmailVerOldTemplate,deviceActEmailTemplate,emailTemplate,forgotPasswordTemplate,lockoutTemplate,pwdlessRegEmailTemplate,selfRegMicroBatchSubErrorEmailTemplate,verificationTemplate,welcomeTemplate. -
Portal:forgotPassTemplate,newCommentTemplate,newPassTemplate,newUserTemplate,ownerNotifyTemplate,selfRegUserTemplate. -
Workflow:template. -
WorkflowAlert:template.
Documentation Inconsistencies
Salesforce's packaging descriptions conflict on Lightning templates. The type definition states that EmailTemplate supports first-generation managed packages only and explicitly notes first-generation packaging support for Lightning templates. However, the uiType description says packaging is supported only for Classic templates.
Lightning packaging eligibility is therefore not stated consistently. The packageVersions field does not resolve this discrepancy or establish support for another packaging model.
Reported Issues
-
A deployment can fail because the destination email folder is missing, even when template paths are correct. In a 2016 Ant report, the accepted solution listed the folder itself as a separate
EmailTemplatemember. Follow-up guidance in 2022 also included the folder metadata file. The report does not establish automatic folder creation from template members alone. See the folder deployment discussion. -
A type-only CLI retrieve can return no results instead of retrieving all templates. A 2020 report using Classic templates was resolved by specifying an explicit folder-qualified member, such as
EmailTemplate:Custom_Template/Claim_Notification. This matches the requirement to enumerate template names rather than use a type-wide wildcard. See the explicit retrieval discussion. -
Missing or incorrect merged values can come from confusing the recipient with the related record. Community guidance in 2016 described
setTargetObjectId()as supplying the recipient andsetWhatId()as supplying the related record. For Visualforce templates, diagnosis also depends onrecipientType,relatedToType, and the record relationships used byrecipientandrelatedToexpressions. These declarations are in the markup, not additional top-level metadata fields. See the merge-context discussion. -
A Visualforce component-access error can reflect an org mismatch rather than a broken template. In a 2015 report, the template rejected a custom component because it required global access. The component with
access="global"existed in a sandbox, while the template being edited was in production. The reported cause was the different orgs, not a need to recreate the template. See the component-access discussion. -
Dependent Apex deployment can fail when an expected email-template field is unavailable in the destination org. A 2023 report showed a compilation failure involving
EnhancedLetterheadIdon the runtimeEmailTemplateobject. The answer linked the symptom to disabled Enhanced Letterhead functionality and suggested requesting feature enablement from Salesforce Support if it was unavailable. This concerns an object field used by Apex, not a top-level element in this metadata definition. See the deployment discussion and the linked Enhanced Letterhead issue.
Common Questions
How do I retrieve all EmailTemplate metadata?
Call listMetadata() for EmailTemplate, then retrieve explicit FolderDeveloperName/TemplateDeveloperName members. EmailTemplate does not support * in package.xml.
Why does my EmailTemplate deployment say it cannot find the folder?
The template path does not prove that the destination folder exists. Reported Ant guidance includes the folder metadata and lists the folder itself as a separate member under EmailTemplate, alongside the Folder/Template members.
Does type=custom mean a Lightning email template?
No. custom means HTML without a letterhead. Read it with uiType: Aloha identifies Classic, while SFX identifies Lightning Experience and requires type=custom.
Why are merge fields blank in my Visualforce email template?
Check the body markup and the actual sending context. Distinguish the recipient supplied through setTargetObjectId() from the related record supplied through setWhatId(). Also inspect recipientType, relatedToType, and the relationships traversed by the merge expressions; relatedEntityType is not a complete inventory of those dependencies.
Can Lightning email templates be included in a managed package?
The official descriptions conflict. The type definition explicitly describes first-generation packaging support for Lightning templates, while the uiType description limits packaging to Classic templates. packageVersions describes referenced components and does not settle the template's packaging eligibility.