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
Athira VenugopalAthira Venugopal 

Mail not received using SingleEmailMessage()

I am working in Visual studio code. On the click of a lightning:button, I am calling a javascript method, inside the method I am calling a visual force page using window.open(url), submiting the form in visual force page, I am calling the apex class method to send an email. I got the message as 'Email Sent !!!,  but the mail was not received.

portion of JS

 openMail(event) {
 window.open('/apex/TestMail', 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
  
}
VF Page
TestMail


<apex:page controller="singleEmailExample">
 <apex:form >
Email Address : <apex:inputText value="{!toAddress}" />
 <apex:commandButton value="SendEmail" action="{!sendingEmail}"/> <br/>
  Email Status :<b> {!message}  </b>
 </apex:form>
</apex:page>

apex class

public with sharing class singleEmailExample {
    public string toAddress{get;set;}
    public string message{get;set;}
    public PageReference sendingEmail(){
        Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
        String[] sendingTo = new String[]{toAddress};
        semail.setToAddresses(sendingTo);
        //String[] sendingToBccAdd = new String[]{‘XXXX@gmail.com’};
       // semail.setBccAddresses(sendingToBccAdd);
       // String[] sendingTocAdd = new String[]{‘XXXXX@gmail.com’};
      // semail.setCcAddresses(sendingTocAdd); */
        semail.setSubject('Single Email message Example');
        semail.setPlainTextBody('Hello!!!!!This is a test email to test single email message program');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
        message='Email Sent !!!';
        return null;
    }
}

Please help me , I tried a lot, and got disappointed
AnudeepAnudeep (Salesforce Developers) 
Hi Athira - I suggest reviewing email logs

Quick Find ---> Email Logs---> Request an Email Log.

This can confirm whether an email has been triggered or no.
Athira VenugopalAthira Venugopal

Hi Anudeep,
I have requested an email log. Now I am getting an error like this:
SendEmail failed. First exception on row 0; first error: SINGLE_EMAIL_LIMIT_EXCEEDED
AnudeepAnudeep (Salesforce Developers) 
Hi Athira - You are hitting a governor limit. See this document to learn how to check the usage https://help.salesforce.com/articleView?id=000331939&type=1&mode=1

There is a limit on the number of emails you can send from Apex, this is 5,000 per 24 hours and you would need to raise a case and engage with Salesforce to see if you can get this raised.

Also, look at this post around how to avoid this error

If you find this information helpful, please mark this answer as Best. It may help others in the community

Regards, 
Anudeep