Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am currently working in a Config-Only sandbox. I have a unit test that is continually failing with the following error message:

System.EmailException: SendEmail failed. First exception on row 0; first error: NO_MASS_MAIL_PERMISSION, Single email is not enabled for your organization or profile. Single email must be enabled for you to use this feature.: []

The interesting thing is that this unit test passes just fine in production. The unit test is for a batchable class. The error is occurring in the finish method on the Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); call. The finish method is:

global void finish(Database.BatchableContext bc) {
    AsyncApexJob a = [
        Select Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email
        From AsyncApexJob
        Where Id = :bc.getJobId()
    ];

    // Send an email to the Apex job's submitter notifying of job completion.
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    String[] toAddresses = new String[] {a.CreatedBy.Email};
    mail.setToAddresses(toAddresses);
    mail.setSubject('Batch job complete with status: ' + a.Status);        
    String body = 'Batch job completed.';
    body += '\nThe batch job processed ' + a.TotalJobItems + ' batches with '+ a.NumberOfErrors + ' failures.';
    body += '\nJob Results: ' + a.Id;
    mail.setPlainTextBody(body);
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}

I recently refreshed the sandbox from production and made no permission changes, so I have no idea why one org would be failing while the other is working just fine. The user I am attempting to run this class with is a System Administrator. The System Administrator profile has the Mass Email and Send Email permission selected. Has anyone run into an error like this before?

share|improve this question
    
This is really odd behavior since everything looks right, can you post your test class/method to see if I can duplicate this error at all? –  jonnybro Feb 26 '13 at 22:38

1 Answer 1

up vote 16 down vote accepted

Have you checked the "Access to Send Email" option under Administration Setup - Email Administration - Deliverability? It's new feature in Spring 13.

share|improve this answer
2  
This was it! I have no idea how this happened (I would assume a sandbox refresh would copy that value over, but the prod system has All Email selected while the sandbox was System Email Only. Changing that value to match prod got the tests passing. Awesome work! Thanks! –  Jesse Altman Feb 27 '13 at 13:12
2  
Sandboxes created since Spring '13 default to "System Email Only" which I believe is intended to stop you from inadvertently sending out messages from your test system. –  Doug B May 9 '13 at 8:10
1  
note also that testmethods do not send emails (which of course, is good) even if All Email is set. –  crop1645 Jun 15 '13 at 0:54
    
for the record, all refreshed sandboxes are set to System Email only : help.salesforce.com/… –  Samuel De Rycke Oct 2 '13 at 13:46
    
Have you checked the "Access to Send Email" option under Administration Setup - Email Administration - Deliverability? It's new feature in Spring 13. Tried the above. It helped –  Venkata Aug 3 at 16:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.