C#實(shí)現(xiàn)按數(shù)據(jù)庫郵件列表發(fā)送郵件的方法
更新時(shí)間:2015年07月15日 16:59:12 作者:DTC2
這篇文章主要介紹了C#實(shí)現(xiàn)按數(shù)據(jù)庫郵件列表發(fā)送郵件的方法,涉及C#讀取數(shù)據(jù)庫及通過自定義函數(shù)發(fā)送郵件的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
本文實(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();
希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C#實(shí)現(xiàn)裝箱與拆箱操作簡單實(shí)例
這篇文章主要介紹了C#實(shí)現(xiàn)裝箱與拆箱操作,對于新手理解裝箱與拆箱有一定的幫助,需要的朋友可以參考下2014-07-07Unity的IPreprocessBuild實(shí)用案例深入解析
這篇文章主要為大家介紹了Unity的IPreprocessBuild實(shí)用案例深入解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05C#?Unity使用正則表達(dá)式去除部分富文本的代碼示例
正則表達(dá)式在我們?nèi)粘i_發(fā)中的用處不用多說了吧,下面這篇文章主要給大家介紹了關(guān)于C#?Unity使用正則表達(dá)式去除部分富文本的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-03-03Winform實(shí)現(xiàn)抓取web頁面內(nèi)容的方法
這篇文章主要介紹了Winform實(shí)現(xiàn)抓取web頁面內(nèi)容的方法,代碼只有短短幾行,但是功能很實(shí)用,需要的朋友可以參考下2014-09-09