向从数据库读取的多个用户发送电子邮件. [英] Send Email To multiple users that is read from database.

查看:123
本文介绍了向从数据库读取的多个用户发送电子邮件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我想发送电子邮件来设置通过单击按钮即可从数据库读取的用户.
任何人都可以帮我.谢谢.

问候
Meenakshi

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

推荐答案

发送很容易:
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.


根据您的设置更改连接字符串中的数据库设置
change the database settings in connectionstring as per your settings
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);
   }


您好,您可以访问此网站的朋友,可能对您有所帮助
Hello friend u can visit this site, may be helpfull for u http://www.emailarchitect.net/easendmail/kb/csharp.aspx[^]


这篇关于向从数据库读取的多个用户发送电子邮件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆