messaging:attachment

Compose an attachment and append it to the email.

Example 

1<messaging:emailTemplate recipientType="Contact"
2	relatedToType="Account"
3	subject="Case report for Account: {!relatedTo.name}"
4	replyTo="support@example.com">
5
6	<messaging:htmlEmailBody>
7	<html>
8		<body>
9		<p>Dear {!recipient.name},</p>
10		<p>Attached is a list of cases related to {!relatedTo.name}.</p>
11		<center>
12		<apex:outputLink value="https://salesforce.com">
13			For more detailed information log in to Salesforce.com
14		</apex:outputLink>
15		</center>
16		</body>
17	</html>
18	</messaging:htmlEmailBody>
19
20	<messaging:attachment renderAs="PDF" filename="yourCases.pdf">
21	<html>
22		<body>
23		<p>You can display your {!relatedTo.name} cases as a PDF</p>
24		<table border="0" >
25		<tr>
26			<th>Case Number</th><th>Origin</th>
27			<th>Creator Email</th><th>Status</th>
28		</tr>
29		<apex:repeat var="cx" value="{!relatedTo.Cases}">
30		<tr>
31			<td><a href =
32			     "https://na1.salesforce.com/{!cx.id}">{!cx.CaseNumber}
33				</a></td>
34			<td>{!cx.Origin}</td>
35			<td>{!cx.Contact.email}</td>
36			<td>{!cx.Status}</td>
37		</tr>
38		</apex:repeat>
39		</table>
40		</body>
41	</html>
42	</messaging:attachment>
43</messaging:emailTemplate>

Attributes 

Attribute NameAttribute TypeDescriptionRequired?API VersionAccess
filenameStringSets a file name on the attachment. If a filename isn’t provided, one is generated for you. 14.0
idStringAn identifier that other components in the page use to reference the attachment component. 14.0global
inlineBooleanSets the HTTP Content-Disposition header of the attachment in the email to inline. 17.0
renderAsStringIndicates how the attachment is rendered. The default value is "text".Although any MIME type/subtype is a valid renderAs value, Visualforce supports content conversion of only PDFs.Visualforce doesn’t generate other file formats. It only sets the Content-Type field of the HTTP response header to the specified MIME type. Some file formats, such as .xlsx, can fail to render. 14.0
renderedBooleanA Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true. 14.0global

See Also