国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實(shí)現(xiàn)按數(shù)據(jù)庫郵件列表發(fā)送郵件的方法

2020-01-24 01:37:30
字體:
供稿:網(wǎng)友

本文實(shí)例講述了C#實(shí)現(xiàn)按數(shù)據(jù)庫郵件列表發(fā)送郵件的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

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>/// 發(fā)送電子郵件/// </summary>/// <param name="from">發(fā)件人</param>/// <param name="to">收件人</param>/// <param name="subject">郵件主題</param>/// <param name="body">郵件內(nèi)容</param>/// <param name="host">發(fā)送服務(wù)地址(smtp.qq.com)</param>/// <param name="port">發(fā)送郵件服務(wù)器端口(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();

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 体育| 桃园县| 南城县| 噶尔县| 彭州市| 岱山县| 宁明县| 明水县| 离岛区| 南城县| 祥云县| 闻喜县| 榕江县| 巴彦淖尔市| 青海省| 随州市| 巧家县| 石棉县| 安陆市| 开化县| 潞西市| 永修县| 文安县| 红原县| 尚志市| 永宁县| 新宁县| 平远县| 大同市| 乐都县| 皋兰县| 左云县| 深水埗区| 土默特右旗| 镇雄县| 巩义市| 通道| 洛阳市| 犍为县| 鄂尔多斯市| 大竹县|