分类目录

链接

2018 年 6 月
 123
45678910
11121314151617
18192021222324
252627282930  

近期文章

热门标签

新人福利,免费薅羊毛

现在位置:    首页 > Salesforce > 正文
salesforce发送email
Salesforce 暂无评论 阅读(451)

首先,我们要设置一下,否则你是无论怎么怼,你都收不到任何邮件:

Have a look under Setup > Email Administration > Deliverability.
Newly created sandboxes have the default email deliverability set to "System email only."
The options are:

  • No access: Prevents all outbound email to and from users.
  • System email only: Allows only automatically generated emails, such as new user and password reset emails.
  • All email: Allows all types of outbound email. Default for new, non-sandbox organizations.

都看得懂,我就不解释了。

 

  1. publicvoidSendEmail(){
  2. List<User> userlist=[select Id,Email from User where name='Bruce He' limit 1];
  3. List<String> toUserId =newList<String>();
  4. List<String> toAddress =newList<String>();
  5. for(User c:userlist){
  6.             toAddress.add(c.Email);
  7.             toUserId.add(c.Id);
  8. }
  9. EmailTemplate et=[Select id from EmailTemplate where developerName  ='Alert_Clean_Expire_Msg_Error' limit 1];
  10. if(toUserId.isEmpty()|| toAddress.isEmpty()|| et==null){
  11. return;
  12. }
  13. Messaging.SingleEmailMessage mail =newMessaging.SingleEmailMessage();
  14.         mail.setTargetObjectId(toUserId[0]);
  15.         mail.setToAddresses(toAddress);
  16.         mail.setTemplateId(et.id);
  17.         mail.setSaveAsActivity(false);
  18.         system.debug(mail);
  19. Messaging.sendEmail(newMessaging.SingleEmailMessage[]{ mail });
  20. }

 

参考内容:

1.https://salesforce.stackexchange.com/questions/12351/send-test-email-from-sandbox

2.https://developer.salesforce.com/forums/?id=906F00000008z98IAA

3.https://developer.salesforce.com/forums/?id=906F0000000DDszIAG

 

OVER

============ 欢迎各位老板打赏~ ===========

本文版权归Bruce's Blog所有,转载引用请完整注明以下信息:
本文作者:Bruce
本文地址:salesforce发送email | Bruce's Blog

发表评论

留言无头像?