You need to sign in to do that
Don't have an account?
Force.platform
email with attachment from static resource
Hello All,
I am new to salesforce. i want to send email with attachment that stored in static resources. please tell me how to do it
I am new to salesforce. i want to send email with attachment that stored in static resources. please tell me how to do it
For this, you just need to read the document body from the static resource as a blob and then make an instance of attachment and then use the same in your email. Like below
Map<String, Blob> res = new Map<String, Blob>();
for(StaticResource resource:[SELECT Name, Body FROM StaticResource WHERE Name IN ('TC_for_France','TC_for_Italy')])
{
res.put(resource.Name, resource.Body);
}
Messaging.SingleEmailMessage[] messages = new Messaging.SingleEmailMessage[0];
for(Attachment attachmentlst1: attachmentlst)
{
// ... omitted ...
Messaging.Emailfileattachment efa1 = new Messaging.Emailfileattachment();
efa1.setFileName(TCname);
efa1.setBody(res.get(resourceName));
// ... omitted ...
messages.add(mail);
}
Messaging.sendEmail(messages);
OR
You can store your attachment in the document rather storing in the static resource and then use that.
Hope this will help you.
Thanks
You should use following code to send email with attachment that stored in static resources.