2015-03-03 93 views
0

我曾經使用這個類發送電子郵件。但現在它不起作用。我是銷售人員的新人。Salesfroce單個電子郵件發送類

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 }); 

回答

0

的代碼是正確的,它爲我工作。您可能會設置一個電子郵件日誌,如here所示,以查看該電子郵件是否未收到郵件。

Sreenish

+0

感謝您的答覆。現在我正在收到電子郵件。 – 2015-03-10 05:32:50

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);