文本电子邮件模板不会进入邮件

时间:2017-05-30 10:17:44

标签: apex

As per the requirement I am sending a pdf file attachment to some email ids,I thought to include some static text to show in the email and i created one text template and added in the code ,but the text is not showing in the email.

这是代码 我使用setTemplateId来显示模板......

 Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
            attach.setContentType('application/pdf');          
            attach.setFileName(************************);
            attach.setInline(false);
            attach.Body = body;

            Messaging.SingleEmailMessage mail = new 
            Messaging.SingleEmailMessage();
            EmailTemplate et=[Select id from EmailTemplate where  
            name=:'CSPdfEmailtemplate'];
            mail.setUseSignature(false);
            mail.setToAddresses(Emailids);
            mail.setTemplateId(et.id);//here i am giving the id of template
            mail.setBccSender(true); 

1 个答案:

答案 0 :(得分:0)

documentation使用模板的singleEmailMessage需要具有setTargetObjectId(targetObjectId)的联系人,用户或潜在客户的id,因此您需要添加它。