How to send email from APEX with an attachment.

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName(‘test.pdf’); //File Name
efa.setBody(someFile);
efa.setContentType(‘application/pdf’); // File type
email.setSubject( ‘adada’ );
email.setToAddresses( new String[] {‘[email protected]’} ); // List of email ids.
email.setPlainTextBody( ‘Tjis is test’ );
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
Messaging.SendEmailResult [] r =
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

Leave your vote

0 points
Upvote Downvote

Comments

0 comments

Leave a Reply

Your email address will not be published. Required fields are marked *