-
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[] {'ganesh.maharana@janbask.com'};
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

The Perks of Getting a Salesforce Certification
Certifications are the way to go these days if one is looking to upskill and grow their career. Degrees are great, but a course certification…

Exciting Features Introduced at Dreamforce 2021 | Salesforce
We are just few weeks out of Dreamforce 2021, but already most of us have started missing it and nostalgically looking forward to the events…

Comparing Salesforce Lightning With Salesforce Classic
The executive's customer relationship is very important to the collaboration with the association's present and future clients, especially in the current scenario, which is full…
Popular Salesforce Videos
Salesforce Spring 22 Release Dates and Preview!
Watch this video to learn about the Salesforce Spring 22 Release Dates and Preview. Timecodes 0:00 - Intro & Overview 1:32 - Spring 22 Release…
Salesforce Field Service Scheduling Optimization | AblyPro Webinar
Revolutionize and Level Up Your Game in Services Business With Field Service With Salesforce Field Service on your side, businesses can reduce travel time, improve…
Top 10 Reasons to Learn Salesforce | Why Should you Learn Salesforce in 2021
The "Top 10 Reasons to Learn Salesforce" video will give you good reasons to learn and start your career in Salesforce. We will address the…