-
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
Why Get Your Business Started with Salesforce Sustainability Cloud?
Salesforce Sustainability Cloud is a powerful platform designed to help companies track, analyze, and report on their sustainability performance. The tool provides a comprehensive set…
4 Customer Centric Approaches for Small and Medium Sized Businesses | Salesforce
Good businesses think of customer satisfaction but great businesses think of customer delight. The customer experience (CX) is one of the key differentiators for any…
Fast Track your Marketing Activities and Enhance User Experience with DemandBlue's Salesforce Marketing Cloud Accelerators
Salesforce Marketing Cloud is one of the most used digital marketing platforms. DemandBlue’s set of Marketing Cloud and Pardot accelerators are uniquely backed by a decade of…
Popular Salesforce Videos
Salesforce Communities: 5 Powerful Ways to Drive Growth
Salesforce Communities are brand spaces designed specifically for Salesforce customers to connect with the community outside their org (i.e., employees, partners, and customers) and collaborate…
Basic Concepts of Salesforce | Salesforce Training Online
This video session on Salesforce online training covers the basic concepts of Salesforce and will give intense knowledge on Salesforce at a very high level.…
4 Salesforce Report Formulas To Enhance Your Sales Process
Salesforce is a highly effective tool that can help businesses manage their customer relationships and sales processes. In this video, you will learn 4 helpful…