messaging:emailTemplate
Defines a Visualforce email template. All email template tags must be wrapped inside a single emailTemplate component tag. emailTemplate must contain either an htmlEmailBody tag or a plainTextEmailBody tag. The detail and form components are not permitted as child nodes. This component can only be used within a Visualforce email template. Email templates can be created and managed through Setup | Communication Templates | Email Templates.
Example
1<messaging:emailTemplate recipientType="Contact"
2 relatedToType="Account"
3 subject="Your account's cases"
4 replyTo="cases@acme.nomail.com" >
5
6 <messaging:htmlEmailBody >
7 <html>
8 <body>
9 <p>Hello {!recipient.name}--</p>
10 <p>Here is a list of the cases we currently have for account {!relatedTo.name}:</p>
11 <apex:datatable cellpadding="5" var="cx" value="{!relatedTo.Cases}">
12 <apex:column value="{!cx.CaseNumber}" headerValue="Case Number"/>
13 <apex:column value="{!cx.Subject}" headerValue="Subject"/>
14 <apex:column value="{!cx.Contact.email}" headerValue="Creator's Email" />
15 <apex:column value="{!cx.Status}" headerValue="Status" />
16 </apex:datatable>
17 </body>
18 </html>
19 </messaging:htmlEmailBody>
20
21 <messaging:attachment renderas="pdf" filename="cases.pdf">
22 <html>
23 <body>
24 <h3>Cases currently associated with {!relatedTo.name}</h3>
25 <apex:datatable border="2" cellspacing="5" var="cx" value="{!relatedTo.Cases}">
26 <apex:column value="{!cx.CaseNumber}" headerValue="Case Number"/>
27 <apex:column value="{!cx.Subject}" headerValue="Subject"/>
28 <apex:column value="{!cx.Contact.email}" headerValue="Creator's Email" />
29 <apex:column value="{!cx.Status}" headerValue="Status" />
30 </apex:datatable>
31 </body>
32 </html>
33 </messaging:attachment>
34
35 <messaging:attachment filename="cases.csv" >
36 <apex:repeat var="cx" value="{!relatedTo.Cases}">
37 {!cx.CaseNumber}, {!cx.Subject}, {!cx.Contact.email}, {!cx.Status}
38 </apex:repeat>
39 </messaging:attachment>
40</messaging:emailTemplate>Translated Template Example
1<!-- This example requires that Label Workbench is enabled and that you have created the referenced labels. The example assumes that the Contact object has a custom language field that contains a valid language key. -->
2
3<messaging:emailTemplate recipientType="Contact"
4 relatedToType="Account"
5 language="{!recipient.language__c}"
6 subject="{!$Label.email_subject}"
7 replyTo="cases@acme.nomail.com" >
8
9 <messaging:htmlEmailBody >
10 <html>
11 <body>
12 <p>{!$Label.email_greeting} {!recipient.name}--</p>
13 <p>{!$Label.email_body}</p>
14 </body>
15 </html>
16 </messaging:htmlEmailBody>
17
18 </messaging:emailTemplate>Attributes
| Attribute Name | Attribute Type | Description | Required? | API Version | Access |
|---|---|---|---|---|---|
| id | String | An identifier that allows the emailTemplate component to be referenced by other components in the page. | 14.0 | global | |
| language | String | The language used to display the email template. Valid values: Salesforce-supported language keys, for example, "en" or "en-US". Accepts merge fields from recipientType and relatedToType. | 18.0 | ||
| recipientType | String | The Salesforce object receiving the email. | 14.0 | ||
| relatedToType | String | The Salesforce object from which the template retrieves merge field data. Valid objects: objects that have a standard controller, including custom objects Visualforce supports. | 14.0 | ||
| rendered | Boolean | A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true. | 14.0 | global | |
| replyTo | String | Sets the reply-to email header. | 14.0 | ||
| subject | String | Sets the email subject line. Limit: 100 characters. | Yes | 14.0 |