在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(){ 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;
}

如果想了解更多的细节,请看如下链接:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_Messaging_instance_methods.htm

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_Messaging_SingleEmailMessage_instance_methods.htm

最新文章

  1. jeesz源码下载
  2. 51nod1265 四点共面
  3. T4模板之初体验(语法)
  4. 关于matlab中特殊字符, 上标和下标
  5. Java的Reference感觉很象C++的指针,但是区别是本质的
  6. PHP中global全局变量的使用
  7. python 字符串格式化 输出
  8. 在ASP.NET MVC中使用DropDownList
  9. Android Studio Error2
  10. 如何完全退出android应用程序
  11. html 浮动元素
  12. 《转》Linux网络编程入门
  13. CFNetwork SSLHandshake failed (-9824) ios 9
  14. PDO数据库操作类
  15. linux常用的监控命令
  16. 多线程:深入Thread.sleep
  17. 用最简单的例子实现jQuery图片即时上传
  18. 05_CRUD操作
  19. InnoDB多版本
  20. PMS及APP安装过程

热门文章

  1. java导出生成word
  2. STL---vector(向量)
  3. 【leetcode】Merge k Sorted Lists
  4. ios 修正waring:Method override for the designated initializer of the superclass &#39;-init&#39; not found
  5. jquery若干问题
  6. 最简单粗暴的http文件列表
  7. Effective C++ -----条款43:学习处理模板化基类内的名称
  8. ant使用指南详细入门教程
  9. FileUpload控件使用初步
  10. 【XLL 框架库函数】 InitFramework