在Salesforce中可以用自带的 Messaging 的 sendEmail 方法去处理Email的发送
请看如下一段简单代码:
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(){ Listattachments = new List (); // 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;}
如果想了解更多的细节,请看如下链接: