I want to write a little generalized function to send email;

Can any one give me good general example.  To include, how to send email to more than one person

public static void sendmail(string strFrom, string strTo, string strSubject, string strBody, string toMailAddress, string txtName)
            MailMessage EmailMsg = new MailMessage();
            EmailMsg.From = new MailAddress(strFrom);
            //    EmailMsg.From = new MailAddress("CustomerService@Aceyourplace.com", "CustomerService@Aceyourplace.com");
            EmailMsg.To.Add(new MailAddress(toMailAddress, txtName));
            EmailMsg.Subject = strSubject;
            EmailMsg.Body = strBody;
            EmailMsg.IsBodyHtml = true;
            // EmailMsg.Priority = MailPriority.Normal;

            SmtpClient MailClient = new SmtpClient();

            // HttpContext.Current.Response.Redirect("mailsent.aspx");

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

the 'to' is simply a string so if you build this string with the email addresses separated by semi-colons then you can pass this string to your function.
Jitendra PatilSr.Software EngineerCommented:
Hi there are two ways you can go with.
1st way
MailMessage msg = new MailMessage();
msg.Body = ....;

SmtpClient smtp = new SmtpClient();
2nd Way using database
using System.Collections; //ArrayList
using System.Data.SqlClient; //SQL
using System.Net.Mail; //email

private void btnSend_Email_Click(object sender, EventArgs e)
            ArrayList list_emails = new ArrayList();
            int i = 0, email = 0;
            sqlConnection1.Open(); //connection to the database.
            SqlCommand cmd_Email = new SqlCommand("Select Email from Email_Table", sqlConnection1);
            SqlDataReader read_Email = cmd_Email.ExecuteReader();
            while (read_Email.Read())
                email = read_Email.GetValue(i).ToString();
                list_emails.Add(email); //Add email to a arraylist
                i = i + 1 - 1; //increment or ++i
            sqlConnection1.Close(); //Close connection
            foreach (string email_to in list_emails)
                MailMessage mail = new MailMessage();
                mail.Subject = "Welcome to C#";
                mail.From = new MailAddress(hold_Account);
                mail.Body = "Test";
                SmtpClient smtp = new SmtpClient("SMTP Server");


Open in new window

hope this helps;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
goodkAuthor Commented:
string strTo="first name  last name" <asdfasdfasdf@yahoo.com>; "nameLname" <jjjllkjljljlkjlj@gmail.com>;

If the above variable is received in my generalized function how would I send this email to the above people?

 EmailMsg.To.Add(new MailAddress(???????));
goodkAuthor Commented:
not sure if i found the answer i was looking for
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.