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
Anshuma YadavAnshuma Yadav 

How we can send emails in bulk from salesforce through API integration ?

Best Answer chosen by Anshuma Yadav
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Anshuma,

Yes we can send the bulk emails with out API integration . Please find the below example for the same.

https://howtodoitinsalesforce.blogspot.com/2016/12/send-mass-emails-from-your-apex-class.html

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Anshuma,

Can you check the below knowledge article for the same.

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_sendemail.htm

If this solution helps, Please mark it as best answer.

Thanks,
 
Anshuma YadavAnshuma Yadav
Thanks Sai Praveen,

Can I send bulk message with the help of apex class without any API integration ?
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Anshuma,

Yes we can send the bulk emails with out API integration . Please find the below example for the same.

https://howtodoitinsalesforce.blogspot.com/2016/12/send-mass-emails-from-your-apex-class.html

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer
Anshuma YadavAnshuma Yadav
Hi Sai Praveen,

Thanks for your reply,
After using above solution for bulk email I am getting an error (SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Email address is invalid: null: [toAddresses, null] Error is in expression '{!sendBulkEmail}' in component <apex:commandButton> in page bulkemailbutton: Class.BulkMail.sendBulkEmail: line 17, column 1 An unexpected error has occurred. Your development organization has been notified.) on my vfp page.

BulkMail.apxc

public class BulkMail {
    public void sendBulkEmail(){
        String subject = 'Regarding Weekly Follow Up.   Regards, Anshuma';
        String body ='This is a testing to send mass email';
        List<Messaging.SingleEmailMessage> listofEmail = new List<Messaging.SingleEmailMessage>();
        List<String> sendTo = new List<String>();
        for(Opportunity opp :[Select Id, Email__c From Opportunity]){
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            sendTo.add(opp.Email__c);
            email.setToAddresses(sendTo);
            email.setSenderDisplayName('XYZ Account');
            email.setSubject( subject ); 
            email.setPlainTextBody( body );
            listofEmail.add(email);
        }
        
        Messaging.sendEmail(listofEmail);
    }
}

BulkEmailButton.vfp

<apex:page controller="BulkMail">
    <apex:form >
    <apex:commandButton value="Send Email" action="{!sendBulkEmail}"/>
    </apex:form>
</apex:page>
 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Can you check in debug logs if you are getting the email address in sendTo list of strings. As the error shows the toadress is null from the code. Can you debug and check it.

Thanks,