在Salesforce中处理Email的发送
2024-08-25 05:28:30
在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;
}
如果想了解更多的细节,请看如下链接:
最新文章
- jeesz源码下载
- 51nod1265 四点共面
- T4模板之初体验(语法)
- 关于matlab中特殊字符, 上标和下标
- Java的Reference感觉很象C++的指针,但是区别是本质的
- PHP中global全局变量的使用
- python 字符串格式化 输出
- 在ASP.NET MVC中使用DropDownList
- Android Studio Error2
- 如何完全退出android应用程序
- html 浮动元素
- 《转》Linux网络编程入门
- CFNetwork SSLHandshake failed (-9824) ios 9
- PDO数据库操作类
- linux常用的监控命令
- 多线程:深入Thread.sleep
- 用最简单的例子实现jQuery图片即时上传
- 05_CRUD操作
- InnoDB多版本
- PMS及APP安装过程
热门文章
- java导出生成word
- STL---vector(向量)
- 【leetcode】Merge k Sorted Lists
- ios 修正waring:Method override for the designated initializer of the superclass &#39;-init&#39; not found
- jquery若干问题
- 最简单粗暴的http文件列表
- Effective C++ -----条款43:学习处理模板化基类内的名称
- ant使用指南详细入门教程
- FileUpload控件使用初步
- 【XLL 框架库函数】 InitFramework