Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
SmtpClient smtpClient = new SmtpClient();
                      MailMessage message = new MailMessage();
                      try
                      {
                          StringBuilder sb = new BAL.PageContent().EmailList();
                          MailAddress fromAddress = new MailAddress("info@captorsolutions.com");
                          message.From = fromAddress;//here you can set address
                          message.To.Add(sb); //here you can add multiple to
                          message.Subject = "Feedback";//subject of email
                          message.CC.Add("cc@site.com");//ccing the same email to other email address
                          message.Bcc.Add(new MailAddress("bcc@site.com"));//here you can add bcc address
                          message.IsBodyHtml = false;//To determine email body is html or not
                          message.Body = @"Plain or HTML Text";
                          smtpClient.Send(message);


getting an error at message.To.Add(sb).
can we add email list in stringbuillder?
Thanking you.
Posted

Multiple e-mail addresses must be separated with a comma character (",")

If that is right, just call

message.To.Add(sb.ToString());



Cheers
 
Share this answer
 
As Mario said, multiple email id needs to be specified in "," separated. So make sure the return email list has the coma separated email ids.
Thanks
 
Share this answer
 
Comments
srinivas vadepally 4-Oct-11 3:59am    
hi abhi,
i had done in class
like
sb.append(email+",");
Anything is wrong,please correct me.
Mario Majčica 4-Oct-11 4:21am    
As suggested earlier, call ToString() method on sb will passing it's content as parameter. Make sure that the last character in the sb is not ",".

Cheers
Abhijit Jana 4-Oct-11 5:17am    
yes. absolutely right !!
Abhijit Jana 4-Oct-11 5:17am    
Hi, as per your code, you email id string should be like,
emaillist="tt@test1.com,tt@test2.com,tt@test3.com,";
where last "," is extra. you have to take care of that.
use
message.To.Add(sb.ToString());
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900