本文实例讲述了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 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#实现按数据库邮件列表发送邮件的方法全部内容,希望文章能够帮你解决C#实现按数据库邮件列表发送邮件的方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)