在Salesforce中能夠用自帶的 Messaging 的 sendEmail 方法去處理Email的發送xcode
請看以下一段簡單代碼:spa
public boolean TextFormat {get;set;} public string EmailTo {get;set;} public string EmailCC {get;set;} public string EmailBCC {get;set;} public string EmailSubject {get;set;} public string EmailBody {get;set;} public string MoreAttachName1 {get;set;} public blob MoreAttachBody1 {get;set;} public string MoreAttachName2 {get;set;} public blob MoreAttachBody2 {get;set;} public string MoreAttachName3 {get;set;} public blob MoreAttachBody3 {get;set;} public PageReference Send(){ List<Messaging.EmailFileAttachment> attachments = new List<Messaging.EmailFileAttachment>(); // Add attachments if(MoreAttachBody1 != null) attachments.add(CreateEmailAttachment(MoreAttachName1, MoreAttachBody1)); if(MoreAttachBody2 != null) attachments.add(CreateEmailAttachment(MoreAttachName2, MoreAttachBody2)); if(MoreAttachBody3 != null) attachments.add(CreateEmailAttachment(MoreAttachName3, MoreAttachBody3)); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setUseSignature(false); mail.setToAddresses(EmailTo.split(';',0)); if(EmailCC != '') mail.setCcAddresses(EmailCC.split(';',0)); if(EmailBCC != '') mail.setBccAddresses(EmailBCC.split(';',0)); mail.setSubject(EmailSubject); if(TextFormat) mail.setPlainTextBody(EmailBody); else mail.setHtmlBody(EmailBody); if(attachments.size() > 0) mail.setFileAttachments(attachments); // Send the email Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); PageReference page = new PageReference('/'+Id); page.setRedirect(true); return page; } private Messaging.EmailFileAttachment CreateEmailAttachment(string name, blob body) { Messaging.EmailFileAttachment emailAttach = new Messaging.EmailFileAttachment(); emailAttach.setFileName(name); emailAttach.setInline(false); emailAttach.Body = body; return emailAttach; }
若是想了解更多的細節,請看以下連接:code