+ Start a Discussion
Tad Aalgaard 3Tad Aalgaard 3 

In Apex, how can I determine if mass emailing is enabled?

If Email Deliverability is not set to All Email in my sandbox my code will error out when trying to send an email.  How can I check if Email Deliverabitlity is set to All Email in Apex so that I don't receive the NO_MASS_MAIL_PERMISSION errors?
Best Answer chosen by Tad Aalgaard 3
Alain CabonAlain Cabon
Accessing the Email Deliverability via Apex code & API​

https://success.salesforce.com/ideaView?id=08730000000cHBEAA2

so it is still a very good idea.

All Answers

Alain CabonAlain Cabon
Accessing the Email Deliverability via Apex code & API​

https://success.salesforce.com/ideaView?id=08730000000cHBEAA2

so it is still a very good idea.
This was selected as the best answer
AubryAubry
Tad, I know I'm a couple years to late for you, but I found something that was helpful in my encounter with this issue:
Boolean EmailDeliverabilityEnabled = true;
try {
    Messaging.reserveSingleEmailCapacity(1);
    Messaging.reserveMassEmailCapacity(1);
} catch (System.NoAccessException e) {
    EmailDeliverabilityEnabled = false;
}
I included this code in my test class, and skipped any email sends if EmailDeliverabilityEnabled was false.  You might get this same error due to permissions, if you are RunningAs a very limited user, but in general, this should work for detecting whether or not Email Deliverability is currently enabled.
SamHowleSamHowle
This is great @Aubry, thank you! Just added it to my Utility class