We have Schedulable Apex class inside Managed Package which sends us emails (using Messaging.SingleEmailMessage) about our package performance.
Short code example :
global without sharing class SchedulablePerformanceActivityCheck implements Schedulable {
global String emailAddress = 'vitaliy@vitalik.vitalii';
global void execute(SchedulableContext sC) {
try {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(emailAddress);
mail.setCcAddresses(emailAddress);
mail.setReplyTo(emailAddress);
mail.setSenderDisplayName('Vitaliy');
mail.setSubject('Performance check');
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setPlainTextBody('some data');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
} catch (Exception ex) {
System.debug(ex.getMessage());
}
}
}
In some organizations we get next error :
"NO_MASS_MAIL_PERMISSION, Single email is not enabled for your organization or profile".
And based on this questions and the answer to it :
We should change the "Access level" parameter to "All Emails", and it makes sense.
In all orgs where it fails Access level = "System Email only"
So my question is :
Can we send email from the Managed Package without changing the Access level config ?
Is there any way/trick to go around this ?
Any help will be appreciated.
Thank you.