-
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
Marketing Cloud Overview in 2024
This article explores Salesforce Marketing Cloud, the exclusive Einstein-powered marketing platform built on the world's most trusted CRM. Designed to foster lasting customer relationships, it…
An Introduction to Salesforce Enterprise Social Network
Billions of people use social networking platforms to stay connected with their family, friend, and business associates. Now, entrepreneurs need a customized corporate networking podium…
Popular Salesforce Videos
Lightning Component Development - Applying Stylesheet, Create Basic Lightning Component
Welcome to Lightning Component Development Sessions. This is the initiative to help Salesforce Community in learning Lightning which we believe is future of Salesforce. Check…
What is Salesforce | Salesforce CRM Tutorial For Beginners | Salesforce Training
This Salesforce Training Video will help you understand what is a CRM ( Customer Relationship Management ), why we need Salesforce CRM and how some…
How to Setup Salesforce Customer Community?
Step by step Salesforce tutorial for quickly setting up a Customer Community with Customer Service (Napili) Template.