Send mails using Messaging.SingleEmailMessage to multiple email ids.
Provide email address in list and assign in to toAddress.
Apex Class:
public class sendMail
{
public sendMail()
{
List<String> emails=new List<String>();
emails.add('arunvictor93@gmail.com');
emails.add('arun.garg@girikon.com');
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.toAddresses = emails;
message.subject = 'Hi Salesforce';
message.plainTextBody = 'This is the message body.';
Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
if (results[0].success)
{
System.debug('The email was sent successfully.');
} else
{
System.debug('The email failed to send: ' + results[0].errors[0].message);
}
}
}
0 comments:
Post a Comment
If you have any doubts, please let me know.