手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#实现按数据库邮件列表发送邮件的方法
C#实现按数据库邮件列表发送邮件的方法
摘要:本文实例讲述了C#实现按数据库邮件列表发送邮件的方法。分享给大家供大家参考。具体实现方法如下:usingSystem;usingSystem...

本文实例讲述了C#实现按数据库邮件列表发送邮件的方法。分享给大家供大家参考。具体实现方法如下:

using System; using System.Net; using System.Net.Mail; using System.Text; using System.Threading; delegate void sendDelegate(string from, string to, string subject, string body, string host, int port, string userName, string password); /// <summary> /// 发送电子邮件 /// </summary> /// <param name="from">发件人</param> /// <param name="to">收件人</param> /// <param name="subject">邮件主题</param> /// <param name="body">邮件内容</param> /// <param name="host">发送服务地址(smtp.qq.com)</param> /// <param name="port">发送邮件服务器端口(25) int型</param> /// <param name="userName">用户名</param> /// <param name="password">密码</param> public void sendmail(string from, string to, string subject, string body, string host, int port, string userName, string password) { MailMessage message = new MailMessage(from, to, subject, body); message.IsBodyHtml = true; message.BodyEncoding = Text.Encoding.UTF8; message.Attachments.Add(new Attachment("c:log.log")); SmtpClient client = new SmtpClient(host, port); client.Credentials = new NetworkCredential(userName, password); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Send(message); } SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Data Source=(local);Integrated Security=SSPI;Initial Catalog=db_showHouse"; //打开连接 conn.Open(); SqlCommandcmd = new SqlCommand("select Email from Employee", conn); SqlDataReader drNew = cmd.ExecuteReader(); if (drNew.HasRows) { while (drNew.Read()) new sendDelegate(sendmail).BeginInvoke("someone@somecompany.com",drNew[0].ToString(),"subject","body","smtp.somescompany.com",25,"userName","password"); } drNew.Close();

希望本文所述对大家的C#程序设计有所帮助。

【C#实现按数据库邮件列表发送邮件的方法】相关文章:

自定义实现Json字符串向C#对象转变的方法

c# 获取数据库中所有表名称的方法

c#实现无标题栏窗口的拖动

C#删除文件目录或文件的解决方法

C#保存图片到数据库并读取显示图片的方法

C#访问PostGreSQL数据库的方法

C#中隐式运行CMD命令行窗口的方法

使用C#开发Socket通讯的方法

C#中将ListView中数据导出到Excel的实例方法

C#实现图片分割方法与代码

精品推荐
分类导航