Monitoring email logs

There's another debug log we should be aware of—the email log. This is required when we want to debug emails sent from Salesforce.

We won't cover the entire email log configuration, but there is something that we sometimes forget to configure when dealing with emails and sandbox organizations: email deliverability.

This simple configuration tells Salesforce which kind of email you want to send from your organization (it works in production organizations as well).

Go to Setup | Email | Deliverability:

Email deliverability setting

You can set the deliverability to any of the following options:

  • No access: No email will ever be sent from Salesforce.
  • System email only: Only system emails will be sent, such as sharing calculations or Apex error notifications.
  • All email: Every kind of email will pass through the Salesforce email servers.
When refreshing a sandbox, this setting is automatically set to System email only, so as to avoid unwanted automations being executed after you have set up your testing environment.
While creating a trial organization (when starting a new Salesforce project for a customer, you start from a trial, which is then promoted to the definitive production organization), this setting cannot be edited, and its default setting is System email only . If this happens, don't panic—just raise a case with Salesforce Support.

Now that you are sure that the emails are sent, go to Setup | Environments | Logs | Email Log Files, and you will see the following page:

Email Logs page

You can request email logs up to 30 days in the past with no more than 7 days per request. Once you request an email log with the only available button on the interface, choose the correct time frame, set up the domain names or email address for the recipients (if needed), and wait for Salesforce to notify you when the ZIP file is ready.

The ZIP contains a CSV with all the emails sent in the given time frame, which you can use to find out whether emails are not being sent, and for what reason. No body or subject is placed in this CSV, just information pertaining to deliverability.

For more details on how these logs are shaped, refer to Salesforce Help at https://help.salesforce.com/articleView?id=email_logs_format.htm&type=5.