Click here to Skip to main content
11,483,983 members (66,098 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: 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 19-Jun-12 0:15am
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 at 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 at 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 at 19-Jun-12 6:24am
correct +5!
Prasad_Kulkarni at 19-Jun-12 8:35am
Thank you Manas!
Stelig at 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?
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
0 Sergey Alexandrovich Kryukov 210
1 Frankie-C 165
2 Raje_ 155
3 OriginalGriff 142
4 Abhipal Singh 108
0 Sergey Alexandrovich Kryukov 8,489
1 OriginalGriff 7,943
2 Sascha Lefèvre 3,114
3 Maciej Los 2,581
4 Richard Deeming 2,370

Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 19 Jun 2012
Copyright © CodeProject, 1999-2015
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