Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hi,
 
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
rp786415
Rate this: bad
good
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.
  Permalink  
Comments
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
good
Please Sign up or sign in to vote.

Solution 3

Try this:
 
Namespaces:
using System.Collections; //ArrayList
using System.Data.SqlClient; //SQL
using System.Net.Mail; //email
Code:
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
            }
            read_Email.Close();
            sqlConnection1.Close(); //Close connection
 
            foreach (string email_to in list_emails)
            {
                MailMessage mail = new MailMessage();
                mail.To.Add(email_to);
                mail.Subject = "Welcome to C#";
                mail.From = new MailAddress(hold_Account);
                mail.Body = "Test";
                SmtpClient smtp = new SmtpClient("SMTP Server");
                smtp.Send(mail);
            }
Ref.: send email to multiple email addresses [^]
  Permalink  
Comments
Manas Bhardwaj at 19-Jun-12 6:24am
   
correct +5!
Prasad_Kulkarni at 19-Jun-12 8:35am
   
Thank you Manas!
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Mathew Soji 330
1 BillWoodruff 260
2 Sergey Alexandrovich Kryukov 240
3 OriginalGriff 216
4 Afzaal Ahmad Zeeshan 208
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,028
3 Manas Bhardwaj 4,539
4 Maciej Los 3,845


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