this question: says that it is "hard" to put a component inside a visualforce email template because ' needs to be a child of component.'. Yet, is there a way to make this work?
We also need to stick to using the visualforce email template and cannot send the email in a different way. The object on which the email template is running has attachments. How can this be done?
Best Answer
I don't think you can do it with pure email template, you'll need some Apex, as suggested in other answers.
<messaging:emailTemplate>
complains as soon as you'd try to stick<apex:repeat>
in there (for example to create<messaging:attachment>
nodes in a loop).Even if you could - try referring to
{!relatedTo.Attachments[0].Body}
somewhere (can be in the plaintextBody tag), you'll get an error:I think the closest it can get is to create the links to attachments (and if I recall correctly - SF converts attachments > 3 MB to links anyway).