• bhoopesh chauhan 6
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

Hello,

 

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.reserveSingleEmailCapacity(2);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'email@domain.com'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('email@domain.com');
mail.setSenderDisplayName('Salesforce Support');
mail.setSubject('New Case Created ');
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setPlainTextBody('Your Case: has been created.');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

Thanks for your help.

I'm trying to use Messaging.sendEmail() in my sandbox and all indications are that it is working:

 

  • Messaging.SendEmailResult.isSuccess() returns TRUE
  • Messaging.SendEmailResult.getErrors() returns an empty list
  • Before/after calls to Limits.getEmailInvocations() indicate that one invocation is being consumed
  • Logs in the Developer Console show what I would expect to see -- the sendEmail() call followed by the body of the message

But the emails just aren't getting to their destination. I have another bit of code that has been around for a while and is quite similar, and it's working just fine -- I test it and an email arrives in my Inbox almost instantly.

 

What can I do to troubleshoot this further? Also, just to fill in some details, the basic architecture of the process I'm trying to automate here is as follows:

 

  • VisualForce email template called E
  • VisualForce page called P
  • code that invokes Messaging.sendEmail() is in the controller associated with P (in the constructor method)

When page P is loaded, the controller's constructor executes and sends an email using the email template E to a test Contact record. At first I was trying to attach a PDF generated by yet another VisualForce page but I commented out this functionality just to see if simplifying things would eliminate the problem. Still no emails in my Inbox.

 

I've also added a call to setBccAddresses() and passed it two additional email addresses of mine, on different domains and hosted by different services from the email address associated with the test Contact -- and the emails don't arrive in those mailboxes, either. All three email vendors provide very straightforward spam control so I have no reason to suspect that the emails are getting blocked -- it just seems like, somehow or other, Salesforce is failing to send these emails /after/ they leave the purview of Apex.

 

What can I do to troubleshoot this problem further?