-
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
Benefits of Salesforce for FinTech: Boosting Efficiency and Scaling Growth
In recent years, the FinTech industry has boomed and transformed how people manage money, invest, and access financial products. However, with this growth, FinTech organizations…
Solving Challenges that Come with the Traditional Salesforce Chatbot Model
Digitization is the name of the game and customers are getting used to this. Chatbots are part of almost every organization’s digital journey. They offer…
OAuth 2.0 Device Authorization Flow in Salesforce
For input-restricted devices that connect to the Internet, instead of authenticating the user directly, the device prompts the user to go to a link on…
Popular Salesforce Videos
Salesforce Introduction | Salesforce Administrator Tutorial for Beginners
Salesforce Administrators work with stakeholders to define system requirements and customize the platform. To put it simply, they enable users to get the most out…
Salesforce Sales Cloud Training | Sales Cloud In Salesforce | Salesforce Tutorial
This Salesforce Sales Cloud Tutorial will help you understand what is leads home page, how to create contacts, how to create products and all creating…
Salesforce for Marketing
Learn how to bring marketing and engagement together. Salesforce Marketing Cloud helps you connect marketing, sales, service, and more on a single platform. Marketers get…