When sending an Email via a Visualforce Email Template, I would like to get all attachments I have for an Opportunity record. I found this page very helpful: Insert Attachment into Visualforce Email Template When linking the documents, it works fine. But this piece of code does not:
<messaging:attachment filename="{!relatedTo.Attachments[0].Name}" renderAs="{!relatedTo.Attachments[0].ContentType}">
{!relatedTo.Attachments[0].Body}
</messaging:attachment>
When I try to save I get the error: Error occurred trying to load the template for preview: "Subscript is invalid because list is empty. Please try editing your markup to correct the problem"
What is the solution here, or how could I integrate one/more components depending on the list index of the attachment to get a similar result?