Salesforce单个电子邮件发送类

时间:2015-03-03 07:25:14

标签: salesforce

我曾使用此课程发送电子邮件。但现在它不起作用。我是salesforce的新手。

List<String> Address = new List<String>();
Address.add('Email address is here');

邮件对象代码如下:

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<Messaging.EmailFileAttachment> allApplicantAttachments = new List<Messaging.EmailFileAttachment>();
Messaging.EmailFileAttachment applicantAttachment = new Messaging.EmailFileAttachment();
PageReference pdf = new pagereference('/apex/gernerateInvoicePdf?Id=a12m00000014ADN');
mail.setToAddresses(Address); 
mail.setSubject('test');
mail.sethtmlBody('hello');
Blob b = pdf.getContent();
//mail.setBody(b);
applicantAttachment.setBody(b);
applicantAttachment.setFileName('test.html');
allApplicantAttachments.add(applicantAttachment);
mail.setFileAttachments(allApplicantAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

2 个答案:

答案 0 :(得分:0)

代码是正确的,它适用于我。您可以按照here设置电子邮件日志,以查看电子邮件是否未送达?

Sreenish

答案 1 :(得分:0)

最后,您要尝试发送到新列表。使用:

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

首先尝试将您的邮件添加到列表中:

List<Messaging.SingleEmailMessage> mailToSend = new List<Messaging.SingleEmailMessage>();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<String> addresses = new List<String>();                
                    addresses.add(emailAddress);
                    mail.setToAddresses(addresses);
                    mail.setPlainTextBody(convertList(contactList));
                    //Add to list then call send with full list
                    mailToSend.add(mail);
                Messaging.sendEmail(mailToSend);