Click here to Skip to main content
15,909,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to send E-mail to set users that is read from database at a Click of a button.
can anyone help me out.Thanks in advance.

Regards
Meenakshi
Posted

Sending is easy: Sending an Email in C# with or without attachments: generic routine.[^]

Where the message comes from is up to you! To send to multiple addresses, add more via the MailMessage.To property, or use the Cc or Bcc properties instead.
 
Share this answer
 
change the database settings in connectionstring as per your settings
C#
public void SendMailToMany()
   {
       String ConnStr = "Data Source=ServerName;Initial Catalog=DBNamae;User ID=UserName;Password='password';";
       String SQL = "SELECT Email  FROM Employee "
          + "WHERE ID IS NOT NULL";
       SqlDataAdapter  Adpt = new SqlDataAdapter(SQL, ConnStr);
       DataSet Email = new DataSet();
       Adpt.Fill(Email);

       string body = "this should be your message body";
       MailMessage message = new MailMessage();
       message.From = new MailAddress("sender@foo.bar.com");
       foreach (DataRow dr in Email.Tables[0].Rows)
       {
           message.To.Add(new MailAddress(dr["Email"].ToString()));
       }
       message.Subject = "This is my subject";
       message.Body = body;

       SmtpClient client = new SmtpClient();
       client.Send(message);
   }
 
Share this answer
 
Hello friend u can visit this site, may be helpfull for u http://www.emailarchitect.net/easendmail/kb/csharp.aspx[^]
 
Share this answer
 

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