Click here to Skip to main content
12,884,261 members (29,669 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# C#4.0

I am building the webservice. I need to send email logically through code.
For example : The User will send a request to webserver. He will choose Multiple recipients by selecting the check boxes. The webserver will get the recipients name and email id list. So please help me that, through code i will be able to send a mail to multiple recipients.

Thanks in advance.
Posted 18-Jun-12 23:15pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

There is a generic routine here for sending email: Sending an Email in C# with or without attachments: generic routine.[^]
All you have to do is add more "To" addresses, or use the CC / BCC list instead.
Manas Bhardwaj 19-Jun-12 6:25am
Nice that you added it as a tip. Wonder that people have stopped using Google and instead ask questions at CP. :)
My 5!
rp786 28-Jun-12 6:06am
Google gives all the solution but Code project gives the best solution out of all the solutions. So people ask question at CP...
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Try this:

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");

Ref.: send email to multiple email addresses [^]
Manas Bhardwaj 19-Jun-12 6:24am
correct +5!
Prasad_Kulkarni 19-Jun-12 8:35am
Thank you Manas!
Stelig 30-Mar-15 9:26am
I am trying to implement a solution like: use a checkbox named "All customers" and if I check it, I send e-mail to all customers addresses.

I have tried the code just as Prasad_Kulkarni posted (modified the sql statement) and I receive the following errors:

1. email = read_Email.GetValue(i).ToString();
->Cannot implicitly convert type 'string' to 'int'

2. mail.From = new MailAddress(hold_Account);
->The name 'hold_Account' does not exist in the current context

Can someone help with this, please?
Member 11970059 17-Mar-16 12:42pm
Did u get a solution to your 1st problem... I m having the same problem.
Member 11970059 17-Mar-16 12:41pm
This above line is showing an error that cannot implicitly convert type string to int.

Plz help asap...
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You can have all the email ids comma separated in the to address. And then send you will be able to send for multiple recipients.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170422.1 | Last Updated 19 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100