You need to sign in to do that
Don't have an account?
Andrew Kulik
Sending emails from Apex in scratch org
I'm trying to send an email from Apex using the code below but when testing this in a scratch org no emails are being recieved. I have verfied the email adress of the test user I'm using and I can see the emails are in the email logs but nothing seems to get sent or recieved.
public static void sendSingleEmailMethod(){ Messaging.reserveSingleEmailCapacity(2); Messaging.SingleEmailMessage mymail = new Messaging.SingleEmailMessage(); String[] toaddresses = new String[] {'xxxxxxxxxxxxx'}; //String[] ccaddresses = new String[] {'xxxxxxxxxxx'}; //String[] bccaddresses = new String[] {'user3@example.com’}; mymail.setToAddresses(toAddresses); //mymail.setCcAddresses(ccAddresses); //mymail.setBccAddresses(bccAddresses); mymail.setReplyTo('support@example.com'); mymail.setSenderDisplayName('Salesforce Support'); mymail.setSubject('An email from Salesforce'); mymail.setPlainTextBody('This email has been sent through Apex'); mymail.setHtmlBody('<p> This email has been sent through Apex</p>'); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mymail }); }
Make sure that your Salesforce org has the necessary email deliverability settings configured. Go to "Setup" > "Email" > "Deliverability" and make sure it's set to "All Email."
Enable "Advanced Email Security Settings".
Setup->Email to Service->Advanced Email Security Settings
You can refer below links which might help you:
https://salesforce.stackexchange.com/questions/162195/why-cant-i-receive-the-email/162196#162196
https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000A7oiySAB
https://help.salesforce.com/s/articleView?id=000386389&type=1
If this information helps, please mark the answer as best. Thank you