Skip to Content

TheBlogReaders.com

Salesforce.com, PHP, MySQL, Javascript, Ajax, Htacces

Send emails with attachments from salesforce using sendgrid

Be First!
by February 25, 2015 Integration, SALESFORCE

Send emails with attachments from salesforce using sendgrid

About Sendgrid:
SendGrid is the world’s largest Email Infrastructure as a Service provider and it as easy as possible to add reliable, scalable email to your application.

SendGrid has been built from the ground up as an API company. make it easy to send email no matter your environment. You can send email over SMTP or HTTP, and even use from sendgrid client libraries.

see more details:
https://sendgrid.com/

About Salesforce:
Salesforce is a leading enterprise customer relationship manager (CRM) application.
http://www.salesforce.com/

Using sendgrid you can send the emails to salesforce leads, contacts, etc

This Apex Toolkit (sendgrid-apex) allows you to quickly and easily send emails through SendGrid using Salesforce Apex.
https://github.com/sendgrid/sendgrid-apex

To install SendGrid Apex Toolkit in your Salesforce Org please use the below link:
https://login.salesforce.com/packaging/installPackage.apexp?p0=04tF0000000SwjP

sendgrid-apex
You can rewrite your code as per your business requirement:

Blob att = pdf.getContentAsPDF();
public static void send(String emailRecipient, String emailSubject, String emailBody, Blob att){

  SendGrid sendgrid = new SendGrid(‘username’, ‘password’);

SendGrid.email email = new SendGrid.Email();
email.addTo(emailRecipient);
email.setFrom(user.Email);
email.setFromName(user.Name);
email.setSubject(emailSubject);
email.setText(emailBody.trim());
email.setHtml(emailBody.trim());
email.addAttachmentStream(“attachment.pdf”, att);

String response = sendgrid.send(email);
}

(799)

Previous
Next

Leave a Reply