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
Kavya SarrajuKavya Sarraju 

Error:SendEmail failed. First exception on row 0; first error: SINGLE_EMAIL_LIMIT_EXCEEDED, Failed to send email: []

Hi All,

By using Single-email-Message i am sending email to internal users through apex but i am getting error.
Error:SendEmail failed. First exception on row 0; first error: SINGLE_EMAIL_LIMIT_EXCEEDED, Failed to send email: []

Please help me out on this error

Thanks
Sumitsing Ingle 15Sumitsing Ingle 15

Hi Kavya,
SingleEmailMesssage is having limits in Salesforce. Using the API or Apex, you can send single emails to a maximum of 1,000 external email addresses per day. For more about limits refer https://login.salesforce.com/help/pdfs/en/salesforce_app_limits_cheatsheet.pdf 

It is possible that you are calling the Messaging.sendEmail(yourSingleEmailMessage); in a loop. To avoid this you can add these emails in List<SingleEmailMeassage> e.g. mails inside the loop and use Messaging.sendEmail(mails) outside the loop.

 

ManojjenaManojjena
Hi Kavya ,

You can hit email server 10 times per transaction ,So if you will call send or SendEmail method inside for loop it wil hit the server more then 10 times it will throw you error .
 
List<Messaging.SingleEmailMessage> mailList =  new List<Messaging.SingleEmailMessage>();
for(){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

//Add all email methods 
mailList.add(mail);
}
Messaging.sendEmail(mailList);

So here it will hit the email server once per tansaction .
Let me know if it helps !!
Thanks 
Manoj
surasura
best way to avoid this limit is to send mails to Salesforce users rather than email addresses , you can do that by using SetTargetobjectid(Id userId) method .Mails send in this manner does not count against your governor limits
eg:
Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
msg.setTargetObjectId(userId);
msg.setSaveAsActivity(false);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { msg });

 
Kavya SarrajuKavya Sarraju
Hi  Sura & Manoj,

Thanks for suggesting me,

As I have already writen the code same as like above you said. But still I  am facing the same problem.

       Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();        
        list <string>  ccAddresses = new list<String>     {'test@gmail.com'};
        mail.setTargetObjectId(con.id);
        mail.setCCAddresses(ccAddresses);
        mail.setReplyTo('business@3w01u74qjv64wenut3g4mpkty9r31s5yyyttwk8gi6q2y36em.9-114ixeaa.ap1.apex.salesforce.com');     
        mail.setSubject(EmailSubject);        
        mail.setHtmlBody(EmailBody);
        mail.setplainTextBody(TextEmail);                 
        mail.saveAsActivity = false;
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});


 
ManojjenaManojjena
Hi Kavya ,

Can you plz post your code and tell the exact error you are getting .

If notpossble to pste the code plz send to my email (manojjena20@gmail.com) fo rwhich I can helpo you to solve the issue .
Sumitsing Ingle 15Sumitsing Ingle 15
Hi Kavya,

Is there any possibility that you have written above code in for loop ?? Can you please share the code and exact error message ?