-
I am new to salesforce. i want to send email with attachment
I am new to salesforce. i want to send email with attachment that stored in static resources. please tell me how to do it
Answer-
public class EmailStaticResource {
public void StaticresourceDataAsEmail(){
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setUseSignature(false);
email.setSaveAsActivity(true);
email.setSubject('Send Email using staticResource as body of mail ');
String[] toAddresses = new String[] {'[email protected]'};
email.setToAddresses(toAddresses);
email.setHtmlBody('<html><body>Dear devoplers<b>See the code for Email service</b></body></html>');
StaticResourcesr = [Select Name, Id, Body From StaticResource where Name = 'Document'];
Blob tempBlob = sr.Body;
Messaging.EmailFileAttachmentefa = new Messaging.EmailFileAttachment();
efa.setBody(tempBlob);
efa.setFileName('attachment.pdf');
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
Messaging.SingleEmailMessage[] emailList = new Messaging.SingleEmailMessage[] {email};
Messaging.sendEmail(emailList);
}
}
Log In to reply.
Popular Salesforce Blogs
![salesforce mvp shonnah](https://images.forcetalks.com/wp-content/uploads/2020/08/10140913/salesforce-mvp-shonnah.jpg)
VIP Spotlight - Meet Shonnah Hughes | Salesforce MVP
Many of us know the awkwardness of trying to come up with a fun fact at the beginning of a new class or job. We…
![Summer ’21 Release](https://images.forcetalks.com/wp-content/uploads/2021/06/10175043/Summer-21-Release.jpg)
Salesforce Summer ’21 Release - Highlights You Need to Know About
It’s time for Salesforce’s Summer ’21 Release! Salesforce has once again built a bunch of new features and improvements to ensure we, the users and…
![Salesforce CPQ Summer](https://images.forcetalks.com/wp-content/uploads/2020/06/25165811/Salesforce-CPQ-Summer.jpg)
Top New Salesforce CPQ Summer ’20 Release Features
Hello everybody! The Salesforce Summer ’20 feature releases have been scorching the tracks this summer, and we’ve thoroughly enjoyed writing the reviews for each of…
Popular Salesforce Videos
Creating an Approval Process in Salesforce with Example
Approval Process in Salesforce is an automated process that automates how Salesforce records are approved in your org. Approval Process in Salesforce is a combination…
Meet us at Dreamforce23 - Unleash the Ultimate Business Experience!
Dreamforce 2023 at San Francisco. Save the dates of September 12–14, 2023, and prepare for an unforgettable experience at Dreamforce 2023. Reserve your position by…
4 Benefits of Salesforce Data Services (ETL)
When your enterprise needs to integrate data from a different application, Salesforce Data Services will help your company in Extracting, Transforming, and Loading the gathered…