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
Terence VibanTerence Viban 

Apex EMAIL_QUEUE on Developer Edition

Hi everyone,

I can't send emails from my developer org. I have tried on two separate dev orgs and everytime I look in the System debug logs, all I see is EMAIL_QUEUE. Why are the emails queued indefinitely?

I have also tried the following code snippet :

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    String[] toAddresses = new String[] {''};
    mail.setSubject('Apex Email TEST');
    mail.setPlainTextBody('The Apex Test is finished processing');
    List<Messaging.SendEmailResult> sendRes = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }, true); 


and the emails are still just queued.  Email deliveribility is set to "All Emails"

I have been stuck at this point for a few days and will appreciate any suggestions on what could be wrong. 

Is "" your own email-id ? Is this email-id active ?

Messaging.SendEmail() just queues the email to Email Server and it is sent asynchronously.
It's not sent as soon as your code fires and hence won't be captured in the logs.

Another possibility is the email is being filtered by the recipient domain or going to the SPAM folder rather than the Inbox.

You would receive a failure message via email (on from address used for sending) if there was an error e.g. the mail id soft/hard bounced.

A better way to determine whether the email is actually sent successfully is having a look at the Email Logs (Setup -> Monitor -> Logs -> Email Log Files).
Also, since you are using toAddresses to specify recipient you may have already hit your daily limit to send SingleEmailMessages but in that case you should have received a SingleEmailLimitExceeded exception.
These limits are much lower in Developer Edition and can be easily hit.

Try using setTargetObjectId while sending email to test if its being delivered (rather than toAddresses) which is exempted from these limits. Since you are just testing, you may set it to your own email id as well "setTargetObjectId(UserInfo.getUserId())".
Amit Chaudhary 8Amit Chaudhary 8
Hi Terence Viban,

Please try to execute below code in developer console. Below code is working fine for me
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setToAddresses(new String[] { '' }); // Please add your email id here
email.setSubject('my subject');
email.setPlainTextBody('plain text body');
List<Messaging.SendEmailResult> results = Messaging.sendEmail(new Messaging.Email[] { email });

if (results[0].success)
 System.debug('The email was sent successfully.');
 System.debug('The email failed to send: '	   + results[0].errors[0].message);
Please add your email id in below line.
email.setToAddresses(new String[] { '' }); // Please add your email id here
Please let me know if you any other help.

Some related link for you

Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help

Amit Chaudhary
Terence VibanTerence Viban
Guys thanks for the replies

@Amit - I ran the code above and the logs show me the same message as before "21:19:31.132 (132184407)|EMAIL_QUEUE|[5]|subject: my subject, bccSender: false, saveAsActivity: true, useSignature: true, toAddresses: ... "
I have also looked at all the links you sent before posting. 
I have implemented Apex Email successful for 3 clients in the past and I have an App on the App Exchange that sends automated emails from a batch job. So I have some experience with Apex email. In this particular case I have tried two separate developer orgs. I was already beginning to think that things have changed with respect to sending Apex email from a Dev Org, but if it works for you then I really don't understand what the problem is here. Any other thoughts?

@Jayant: I have tried sending Email with and without setTargetObjectId and in all case the emails are just queued. I also took a look at the email logs and there are no errors. Just the indication that email is queued. I have tried provoking errors, like attaching files greater than 10MB and I get an exception as expected. So there are no errors being thrown and I haven't reached my daily LIMITS either because I haven't even succeeded to send an email once. The problem here is really that for the two Dev orgs I use, the emails are queued indefinitely. Any other thoughts?

Thanks guys

Amit Chaudhary 8Amit Chaudhary 8
Hi Terence Viban,

Above code is working fine for me. Can you please let me know from where you are executing above code.
Please try in developer console...

1) Email cannot be sent from a constructor
2) Test class cannot send an email
3) Please check your organization's email deliverability Setting. (TLS)

User-added image

If Possible then please post your full code.

Amit Chaudhary
Terence VibanTerence Viban
Hi Amit,

I executed the piece of code directly from execute anonymous on Mavensmate. The deliverability setting is set to All Email, this is the first thing I checked. And also the issue with not being able to send email from the constructor or test class, I know already.

I will try a new brand Org and open a case with Salesforce at thesmae time. The fact that I cannot even run the snippet above that runs fine for you is may be an indication that something is wrong with my org. It doesn't really make a difference if I post my own code here or not. I can get the snippet above to send an email.

Thanks for you help Amit.