You need to sign in to do that
Don't have an account?
csbaa
email with atachmanet
Hello Helpers
I would like to know how can I send email with attachment from an apex class
I know how to send mails.
I sew articles about how to attach a VFpage rendered as pdf
but what I need is to attach a file to my email
I am thinking to a static resource
any suggestions?
regards
csbaa
Hi, Please check this out:
All Answers
Go through this link:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound_single.htm
and Get your file into a blob data type and attach that to email using setFileAttachments.
Mark as Answer if it Helped!!
public void sendEmail(){
//File Attachment
Messaging.EmailFileAttachment att = new Messaging.EmailFileAttachment();
att.setFileName('Your File Name');
att.setBody(file body);
att.setContentType('Your file content type(MIME)');
//Single Email
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String[] toAddress = new String[] {'List of email addresses'};
email.setToAddresses(toAddress);
email.setSubject('Email Subject');
email.setPlainTextBody('body of the email');
email.setFileAttachments(new Messaging.EmailFileAttachment[] {att});
// sends the email
Messaging.sendEmailResult[] result = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
System.debug('Is Success '+result[0].isSuccess());
}
Thanks,
Thiyagarajan Selvaraj
Hi, Please check this out:
this was the key: List<StaticResource> resources = [select Id, Name, Body from StaticResource
Regards
csaba