function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nishanth0208nishanth0208 

sending more than 10 emails using SingleEmailMessage class

Hello All,

I 'd an issue regarding sending emails using singleemailmessage class. Heard that we can send 10 * 1000 = 10000 emails per execution (10 arrays, each array to accomodate 1000 emails). Is this true?

But i am unable to send more than 10 emails. Could anyone plz clarify me how to do. PFB my code snippet:

 

            }

for(Permit__c p:permitList){
                 Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
                                    String subject = p.Name+' | '+p.Region__c+' | '+p.Full_State__c+' | '+p.Channel__c+' | Status=Expired';
                                    email.setSubject(subject);
                                    String emailadd = 'abc@xyz.com';
                                    String[] toAddresses = emailadd.split(',');
                                    email.setToAddresses(toAddresses);
                                    email.setHTMLBody( 'email body.' );
                 Messaging.SendEmailResult[] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 

 

 

An error is being thrown when 10 mails are sent and is about to send 11th email.

Plz help!

Best Answer chosen by Admin (Salesforce Developers) 
nishanth0208nishanth0208

Thanks a ton Ankit. Went across your blog.

This helped me out from ur blog.

 

http://devendranatani.blogspot.com

 

List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();

for(User portalUser :lstPortalUser) {

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

string body = 'Hi '+ portalUser.LastName;

mail.setSubject('Test Subject');

mail.setTargetObjectId(portalUser.Id); mail.setSaveAsActivity(false);

mail.setHtmlBody(body); mails.add(mail);

}

Messaging.sendEmail(mails);

 

 

 

All Answers

RaumilRaumil

Hello friend,

 

You can send only 10 mails per transaction using this method which is governer limit of Salesforce. Aditional information can be known from the following link.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound.htm

 

Hope this helps

Raumil Setalwad

Ankit AroraAnkit Arora

If you have conditional Subject and Email Body then I have something for you from my blog :

 

http://forceguru.blogspot.com/2011/03/how-to-send-more-than-10-e-mails.html

 

But if you have everything same and just the recipients are different then you can go with Mass Email.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

nishanth0208nishanth0208

Thanks a ton Ankit. Went across your blog.

This helped me out from ur blog.

 

http://devendranatani.blogspot.com

 

List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();

for(User portalUser :lstPortalUser) {

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

string body = 'Hi '+ portalUser.LastName;

mail.setSubject('Test Subject');

mail.setTargetObjectId(portalUser.Id); mail.setSaveAsActivity(false);

mail.setHtmlBody(body); mails.add(mail);

}

Messaging.sendEmail(mails);

 

 

 

This was selected as the best answer
ca_peterson_oldca_peterson_old

There's something not many people notice about the sendEmail govenor limit: you can only call it 10 times, but there's no (specified) limit on how many emails can be sent per call.

 

Make a list of Messaging.SingleEmailMessae objects, and put all of the emails you want to send in that list, then call Messaging.sendEmail and pass in your list of messages. I've sent more than 10 emails with this method, and I'm not sure what the upper limit is, but you should be able to send at least 100 emails per apex transaction this way.

Ankit AroraAnkit Arora

To get this limit please visit :

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm

 

and read section : "Outbound Email: Limits for Single and Mass Email Sent Using Apex"

 

My blog help when you want to send the email with different subject and body and to multiple users. Adding emails to send email instance will send the same email to all users.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

ca_peterson_oldca_peterson_old

That section only says that you can send to only 1,000 unique email addresses per day from apex.

 

There's no restriction that all emails in a single sendEmail invocation be the same content, in fact I send totally different emails to different users in the same invocation in more than one place.

goabhigogoabhigo

I have been posting about the same every where - discussion boards, help and training, raised a case, commented on blogs, tweeted. Still I didn't get limitation for the size of the list yet. From reading docs and replies to post I understood that you can send emails to 1000 recipients. So I believe our List can contain 1000 (if recipient is one in each), or 500 (if one TO address and one CC),.......

 

Correct me if I am wrong. I have raised a case. Lets see what Salesforce has to say about this.

Rasmus MenckeRasmus Mencke

You should be able to send 100 emails in one call, you can do 10 calls in an Apex request. Alternatively you can look at Batch Apex to scale this up. There are still a daily org limit in place for all orgs. 

 

 

Ricky MartinRicky Martin
@Ankit Arora,
I have used that code but I didnt get the email. So, in which line you are calling this method (global void execute(Database.BatchableContext BC, List<sObject> scope))

I have use following code for checking in Command Edito(Ctrl+E)  No Luck.

Batch_CaseEmail controller = new Batch_CaseEmail() ; 
Integer batchSize = 1; 
database.executebatch(controller , batchSize);

Could you pelase let me knwo to resolve this issue?