You need to sign in to do that
Don't have an account?
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!
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
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
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
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);
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.
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
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.
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.
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.
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?
Send emails to multiple email Ids using Apex.
https://sfdcadda.blogspot.in/2017/05/send-emails-to-multiple-email-ids-using.html