Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am developing a web application, in which i need to send mail to a group of users. Their email ids are saved in a group called MyList. The following code is used to send the mail.
C#
MailMessage mail = new MailMessage();
               
                mail.From = new MailAddress(strSenderEmail);
                //mail.To.Add(new MailAddress(strToEmail));
                mail.To.Add(new MailAddress(MyList));
                mail.Subject = strSubject;
                mail.IsBodyHtml = true;
                AlternateView htmlView = AlternateView.CreateAlternateViewFromString(strBody, null, "text/html");
                htmlView.LinkedResources.Add(logo1);
                htmlView.LinkedResources.Add(logo2);
                mail.AlternateViews.Add(htmlView);
                SmtpClient smtp = new SmtpClient(strMailServer);
                smtp.Send(mail);


But i am getting error at 'mail.To.Add(new MailAddress(MyList));'
saying the email address is not in the correct format.

How can i send a mail to the list called 'MyList'. How can i solve this?

Thanks in advance
Sruthi R
Posted
Updated 1-May-12 23:41pm
v2

1 solution

A MailAddress is a single item, not a list of values. You will have to create a new MailAddress for each item in the list.

BTW: You might want to look at the Cc or Bcc property rather than To - the last one doesn't list them all when it sends it so members of your group don't get each others email address each time.
 
Share this answer
 
Comments
SruthiR 2-May-12 6:19am    
Thanks. Can u please post a sample code which retrieves the email list from the distribution list name.
OriginalGriff 2-May-12 6:32am    
Um. I'll give you a clue: foreach(string addr in MyList)...

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