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

首頁 > 編程 > C# > 正文

C#實現按數據庫郵件列表發送郵件的方法

2019-10-29 21:41:01
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了C#實現按數據庫郵件列表發送郵件的方法,涉及C#讀取數據庫及通過自定義函數發送郵件的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了C#實現按數據庫郵件列表發送郵件的方法。分享給大家供大家參考。具體實現方法如下:

 

 
  1. using System; 
  2. using System.Net; 
  3. using System.Net.Mail; 
  4. using System.Text; 
  5. using System.Threading; 
  6. delegate void sendDelegate(string from, string to, string subject, string body, string host, int port, string userName, string password); 
  7. /// <summary> 
  8. /// 發送電子郵件 
  9. /// </summary> 
  10. /// <param name="from">發件人</param> 
  11. /// <param name="to">收件人</param> 
  12. /// <param name="subject">郵件主題</param> 
  13. /// <param name="body">郵件內容</param> 
  14. /// <param name="host">發送服務地址(smtp.qq.com)</param> 
  15. /// <param name="port">發送郵件服務器端口(25) int型</param> 
  16. /// <param name="userName">用戶名</param> 
  17. /// <param name="password">密碼</param> 
  18. public void sendmail(string from, string to, string subject, string body, string host, int port, string userName, string password) 
  19. MailMessage message = new MailMessage(from, to, subject, body); 
  20. message.IsBodyHtml = true
  21. message.BodyEncoding = Text.Encoding.UTF8; 
  22. message.Attachments.Add(new Attachment("c://log.log")); 
  23. SmtpClient client = new SmtpClient(host, port); 
  24. client.Credentials = new NetworkCredential(userName, password); 
  25. client.DeliveryMethod = SmtpDeliveryMethod.Network; 
  26. client.Send(message); 
  27. SqlConnection conn = new SqlConnection(); 
  28. conn.ConnectionString = "Data Source=(local);Integrated Security=SSPI;Initial Catalog=db_showHouse";   //打開連接 
  29. conn.Open(); 
  30. SqlCommandcmd = new SqlCommand("select Email from Employee", conn); 
  31. SqlDataReader drNew = cmd.ExecuteReader(); 
  32. if (drNew.HasRows) 
  33. while (drNew.Read()) 
  34. new sendDelegate(sendmail).BeginInvoke("someone@somecompany.com",drNew[0].ToString(),"subject","body","smtp.somescompany.com",25,"userName","password"); 
  35. drNew.Close(); 

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巫山县| 张掖市| 时尚| 江口县| 南安市| 南陵县| 岳西县| 罗定市| 英德市| 江油市| 伊宁县| 贡嘎县| 平舆县| 大方县| 泸水县| 界首市| 西盟| 龙胜| 个旧市| 报价| 兴国县| 庐江县| 兴城市| 逊克县| 河东区| 高碑店市| 牡丹江市| 金川县| 吴堡县| 南丰县| 高雄市| 平罗县| 万山特区| 桐庐县| 浦北县| 阿鲁科尔沁旗| 新津县| 密云县| 隆化县| 中西区| 泉州市|