I have a feature that sends emails to final user after an action is completed.

It is done by calling the oncomplete function on a commandButton on a ApexPage.

The testClass for the feature works fine, the same code via Developer console, too.

But, when I try it by using the live feature in a ApexPage, the email never arrives and no exception is thrown.

yes, the "Access level" Deliverability is set to "All email".

The fragment is like so:

EmailTemplate template = templateList[0];
Messaging.SingleEmailMessage  mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[]{objContact.Email});
String htmlBody = template.HtmlValue;
String subject  = template.Subject;
htmlBody        = htmlBody.replaceAll('#CONTACT_NAME#', objContact.Name);
mail.setReplyTo('[email protected]');
Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {mail};
Messaging.SendEmailResult[] results     = Messaging.sendEmail(messages); 

What could be the issue here?

  //always true, but no email comes


When I access the page in a internal approach like so:


it works.

It sounds like a permition...which one?


By looking at email logs, what did I find?

Unauthenticated email from force.com is not accepted due to domain's\r\n550-5.7.26 DMARC policy. Please contact the administrator of force.com domain\r\n550-5.7.26 if this was a legitimate mail. Please visit\r\n550-5.7.26 https://support.google.com/mail/answer/2451690 to learn about the\r\n550 5.7.26 DMARC initiative.

  • What is returned in SendEmailResult's?
    – kurunve
    Commented Nov 29, 2021 at 17:47
  • I have added the code snippet that returns true, but no email comes Commented Nov 29, 2021 at 18:25
  • 2
    Pull email logs and go from there
    – identigral
    Commented Nov 29, 2021 at 18:31
  • You'd need access to every field the template pulls.
    – Adrian Larson
    Commented Nov 29, 2021 at 19:44
  • Regarding the access to fields, I have provided it to every field that template pulls, but no email arrives. Is it supposed to be something related to the type of license of the page? It is set as Guest user license. Related to the log? I could not find anything wrong. The Werid is that the debug shows that the email is sent. Commented Nov 30, 2021 at 0:06

1 Answer 1


I've found the solution.

You should configure your salesforce sandbox to send email through Email Relay. I realized it after checking the emails logs. Over there, the email is not sent. Google, for example, rejected them. All of them.

Go to Setup -> Email Relays and add your own configuration. After, add Setup -> Email Domain Filter.

Important to check the headers of the emails to see that in fact, you have set up it right. After defining relays, the emails will not be sent by Salesforce Admin user anymore. They will be sent by the email provider that you set up.

More details can be found here.








You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .