0

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.

Vitalii Dehnerys
  • 1,583
  • 1
  • 12
  • 35
  • 3
    Package a Remote Site configuration that points to a REST API you create on your PBO and have your package "phone home" using a REST call instead of using an email to send these details... – Phil W Feb 01 '23 at 13:14
  • @PhilW Thanks, It is a good idea. However I have already build a lot of logic which depends on that emails, I have Email Service which handles these email and logs the data. But if I don't get another solution I will go with your option ! – Vitalii Dehnerys Feb 01 '23 at 13:28

0 Answers0