+ Start a Discussion
rupesh ranjanrupesh ranjan 

Problem is not getting mail to List mail of address

Problem is not getting mail to List mail of address  only mail goes to "rupesh@webmindinfotech.com". But i want List of mail that should be fire.

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
     List<String> toAddress =new List<String>();
     String emailadd = 'rupesh@webmindinfotech.com';
 List<String> toAddresses = emailadd.split(';');
     email.setToAddresses(toAddresses );
    email.setSubject(subject);
    email.setPlainTextBody(body);
    email.setBccSender(true);
  Messaging.SendEmailResult [] res = Messaging.SendEmail(new Messaging.SingleEmailMessage[] {email});  
  for ( Messaging.sendEmailResult result : res ) {
           if ( !res[0].isSuccess () ) {
               System.debug ( result  );
           }
           else{
               ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.INFO, 'Email Sent Successfully' );
               ApexPages.addMessage(msg);
           }
       }
  return null;        
}
public SendEmail(){
        body = apexpages.currentpage().getparameters().get('att');
    }
Amit Chaudhary 8Amit Chaudhary 8
Please check below post. I hope that will help you
1) http://amitsalesforce.blogspot.in/2015/11/singleemailmessage-vs-massemailmessage.html
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
    List<String> toAddress =new List<String>();
    String emailadd = 'rupesh@webmindinfotech.com';
	List<String> toAddresses = emailadd.split(';');
	
	email.toAddresses = new String[] { 'rupesh@webmindinfotech.com' };
	//email.setToAddresses( new String[] { 'rupesh@webmindinfotech.com' } ); try this line if above will not work
    //email.setToAddresses(toAddresses ); 
    email.setSubject(subject);
    email.setPlainTextBody(body);
    email.setBccSender(true);
	Messaging.SendEmailResult [] res = Messaging.SendEmail(new Messaging.SingleEmailMessage[] {email});  
	for ( Messaging.sendEmailResult result : res ) 
	{
           if ( !res[0].isSuccess () ) {
               System.debug ( result  );
           }
           else{
               ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.INFO, 'Email Sent Successfully' );
               ApexPages.addMessage(msg);
           }
    }
  return null;        
}
public SendEmail(){
        body = apexpages.currentpage().getparameters().get('att');
    }
Let us know if this will help you
 
sandeep sankhlasandeep sankhla
Hi Rupesh,

In your list only one email address is present so it's going to that email only, Did you check with providing more than one email with ; seperated ?

 String emailadd = 'sandeep.sankhla@trekbin.com;rajesh.kamath@trekbin.com';  I have used this and got email on both the addresses.

Thanks!
rupesh ranjanrupesh ranjan

you have entered sandeep.sankhla@trekbin.com;rajesh.kamath@trekbin.com stacially right??

But my point is "To Address:-  will be any thing dont know (dynamically)" and it should be more than 10.

So Whats the code for this??
sandeep sankhlasandeep sankhla
Hi Rupesh,

Can you elaborate more what exactly is your need? with example so I can help you out? 

As far as I understood you want to send email to approx 10 people and that should be dynamic, so you can get the list and then you can set the list to toAddresses....

Thanks!
Amit Chaudhary 8Amit Chaudhary 8
if your want to send email to single email id please try below code. SingleEmailMessage
public class EmailHelper 
{
 public static void sendEmail() 
 {
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();  
  string body = 'Demo Body ';
  String[] toAddresses = new String[] {'abc@gmail.com'}; 
  mail.setToAddresses(toAddresses);
  mail.setSubject('Test Subject');  
  mail.setSaveAsActivity(false);  
  mail.setHtmlBody(body);  
  Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }  
}
But if you want to send email to mutlipe person together then try below code. MassEmailMessage
public void SendEmail()
{
 List<contact> lstcon=[Select id from contact limit 2];
 List<Id> lstids= new List<Id>();
 for(Contact c:lstcon)
 {
  lstids.add(c.id);
 }
 EmailTemplate et=[Select id from EmailTemplate where name = 'EmailTemplatename' limit 1];
 
 Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
 mail.setTargetObjectIds(lstIds);
 mail.setSenderDisplayName('System Admin');
 mail.setTemplateId(et.id);
 Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
}

Check below post for more info
http://amitsalesforce.blogspot.in/search/label/Email

 
rupesh ranjanrupesh ranjan
can you please give your email Id?? @sandeep sankhla
sandeep sankhlasandeep sankhla
Hi Rupesh,

sandeep.sankhla@trekbin.com is my email id.

Thanks!
rupesh ranjanrupesh ranjan
I have mailed you my Code 
two extensions="AccountSelectClassController,SendEmail"
Send Email is for Mail
and AccountSelectClassController is to select multpile contact Email Id in To Address
Now i need to do is send email to multiple contacts

@Sandeep