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
Haseeb Ahmad 9Haseeb Ahmad 9 

Error sending email - REQUIRED_FIELD_MISSING, Email body is required.: []

Hi Everyone,
Trying to send email from apex and receiving error:

System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Email body is required.: []

Apex Class: 
public with sharing class EmailUtils 
{
    public static void sendEmail(List<String> toAddresses, String senderDisplayName, String subject, String body)
    {       
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.settoAddresses(toAddresses);
        mail.setSenderDisplayName(senderDisplayName);
        mail.setSubject(subject);
        mail.setPlainTextBody(body);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
Test: 
@isTest
private class EmailUtilsTest 
{
    @isTest
    static void testEmailUtils()
    {
        Test.StartTest();
        EmailUtils.sendEmail(new List<String>{'test@test.com'}, 'Unit Test Name', 'Unit Test X', 'Unit Test');
        Integer invocations = Limits.getEmailInvocations();
        Test.stopTest();
 
        System.assertEquals(1, invocations, 'An email has not been sent');
    }
It has 100% code coverage but when I am trying to deploy in production getting that above error. please help, thank you.
​​​​​​​
 
Suraj Tripathi 47Suraj Tripathi 47
Hi Haseeb Ahmad 9,

I think there is no error in your code but When you actually execute it, The body must not be null or empty.
Try and find the reason why your mail body is Empty.

Thanks 
SwethaSwetha (Salesforce Developers) 
HI Haseeb,
A similar discussion is on https://salesforce.stackexchange.com/questions/283764/error-sending-email-required-field-missing-email-body-is-required

Adding to the above user's comment, your code would run successfully when executed in a developer console like
String[] sendingTo = new String[]{'smaddali@abc.com'};
String senderDisplayName='Swetha';
String subject ='Speaker confirmation for the session';
String body ='thank you for speaking at the conference really appericated';
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.settoAddresses(sendingTo);
        mail.setSenderDisplayName(senderDisplayName);
        mail.setSubject(subject);
        mail.setPlainTextBody(body);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

You need to ensure that the method below is getting all the needed parameters which in your case is missing the body

public static void sendEmail(List<String> toAddresses, String senderDisplayName, String subject, String body)

Related: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_outbound_single.htm

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful.Thank you