function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Sending Single Email Message from Sandbox



I'm having a problem sending an email message from the developer console or execute anonymous or final batch statments from within the sandbox.


I have successfully sent the email from the developer console in the production org, but i cannot do the same in the sandbox.


Does anyone know why i would not be able to send from the sandbox?


Here is the code:


Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {''};
mail.setSenderDisplayName('Salesforce Support');
mail.setSubject('New Case Created ');
mail.setPlainTextBody('Your Case: has been created.');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });


Thanks for your help.

Ben DunlapBen Dunlap

Sounds suspiciously like the problem I'm having in my sandbox:


I'm going to deploy the code mentioned in my question to production today and see if it works there -- will update both threads.

Ben DunlapBen Dunlap

No luck in for me in Production, either -- so nevermind, I guess.


Works fine from my sandbox.....maybe log a case

Chirag MehtaChirag Mehta

Newly created sandboxes have the default email deliverability setting System email only.


To configure email deliverability settings, in the sandbox organization, from Setup, click Email Administration | Deliverability. If editable, set the Access level in the Access to Send Email section to All Email


Once set this setting, then you will start receiving emails even from sandbox.


PS: You may not be able to edit the Access level if has restricted your organization’s ability to change this setting.

Mr. KarateMr. Karate
I have my sandbox "Access to Send Email" to All Email and I am still having this problem.  I'm able to recieve test emails from the servers but nothing from apex code comes through.
bhoopesh chauhan 6bhoopesh chauhan 6

Hi seattle_developer,

were you adding an error to the records using addError.
If so then that would cause the entire transaction to roll back and along with it the queued emails.

you can refer: