Activity › Forums › Salesforce® Discussions › How to Send Multiple Emails which are entered from Vf Page
Tagged: Bulk Email, Dynamic Visualforce, Salesforce Email, Salesforce Force.com, Salesforce Visualforce Page
-
How to Send Multiple Emails which are entered from Vf Page
Posted by Shravani on November 18, 2016 at 1:47 PMI have written a controller with vf page which send email which fetched from Account. But I also want to allow user to enter multiple Email Address from vf page. How Can I achieve this?
Thanks In Advance
santhosh replied 8 years, 11 months ago 4 Members · 3 Replies -
3 Replies
-
Hi Shravani,
Use this code
public void SendEmail(List<Id> userids){
Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
List<Id> contactIds = new List<Id> ();
contactIds .add(‘003Q0000005DYvTIAW’);
contactIds .add(‘003Q0000005DYvTIAW’);
mail.setTargetObjectIds(contactIds); mail.setTemplateId(’00XQ0000000HvBNMA0′);mail.setSaveAsActivity(false);
Messaging.SendEmailResult[] sendEmailResults = Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
for (Messaging.SendEmailResult sendEmailResult : sendEmailResults) {
if(sendEmailResult.isSuccess()){ System.debug(‘success’);}
else{ System.debug(
‘error’);}
}
}
Thanks
- [adinserter block='9']
-
Hi Shravani,
I hope this code will be helpful for you…
public with sharing class sendEmail{
public String Email{get;set;}
public String[] toAddresses;
public student__c stu{set;get;}
public sendEmail(){
stu=[select name,id,email__c from student__c];
Email=stu.email__c;
}
public PageReference send(){
String[] toaddress = new String[]{<b>Email</b>};
String[] arrTest = Email.split(‘\\;’);
System.debug(‘arrTest’+’Email :’ + toaddress[0]);
Messaging.SingleEmailMessage email=new Messaging.SingleEmailMessage();
email.SetToAddresses(<b>arrTest </b>);
email.SetSubject(Subject);
email.setTargetObjectIds(object.id);
email.SetPlainTextBody(Emailbody);
email1.SetsenderDisplayName(‘janbask’);
EmailTemplate tem=[select id from EmailTemplate where name=’ganesh’];
email1.setTemplateId(tem.id);
email.setSaveAsActivity(false);
messaging.sendEmailResult[]mesg=Messaging.sendEmail(new Messaging.singleEmailMessage [ ]{email});
if(mesg [0].success) {
System.debug(‘The email was sent successfully.’);
} else {
System.debug(‘The email failed to send: ‘+ mesg [0].errors[0].message);
}
}}
-
The Code Shared helped was very much useful and helpful
Log In to reply.