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); }
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.
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
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,
Can I send bulk message with the help of apex class without any API integration ?
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,
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>
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,