You need to sign in to do that
Don't have an account?
Athira 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
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
Quick Find ---> Email Logs---> Request an Email Log.
This can confirm whether an email has been triggered or no.
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
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