C#實(shí)現(xiàn)異步發(fā)送郵件的方法
本文實(shí)例講述了C#實(shí)現(xiàn)異步發(fā)送郵件的方法。分享給大家供大家參考。具體如下:
下面的代碼可以實(shí)現(xiàn)異步發(fā)送郵件,等郵件發(fā)送出去后會(huì)自動(dòng)調(diào)用回調(diào)函數(shù),這樣在發(fā)送郵件時(shí)就不會(huì)卡住程序不動(dòng)了
MailMessage m = new MailMessage
("item@jb51.net",
"raja@jb51.net",
"This is the subject for the authorized email.",
"This is the body of the authorized mail!...");
// Send the message using authorization
SmtpClient client = new SmtpClient("smtp.jb51.net");
client.Credentials = new NetworkCredential("user", "password");
client.EnableSsl = true;
// Add the event handler
client.SendCompleted += new SendCompletedEventHandler(mail_SendCompleted);
// Send the message asynchronously
client.SendAsync(m, null);
// To Cancel the send
//client.SendAsyncCancel();
void mail_SendCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Cancelled)
Console.WriteLine("Message cancelled");
else if (e.Error != null)
Console.WriteLine("Error: " + e.Error.ToString());
else
Console.WriteLine("Message sent");
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
- c#調(diào)用qq郵箱smtp發(fā)送郵件修改版代碼分享
- c# 實(shí)現(xiàn)發(fā)送郵件的功能
- C# 服務(wù)器發(fā)送郵件失敗實(shí)例分析
- C# Email發(fā)送郵件 對(duì)方打開(kāi)郵件可獲得提醒
- C# SendMail發(fā)送郵件功能實(shí)現(xiàn)
- C#使用windows服務(wù)發(fā)送郵件
- C#編程實(shí)現(xiàn)發(fā)送郵件的方法(可添加附件)
- C#編寫(xiě)發(fā)送郵件組件
- C#使用自帶的email組件發(fā)送郵件的方法
- C#實(shí)現(xiàn)發(fā)送郵件的三種方法
- C# SMTP發(fā)送郵件的示例
相關(guān)文章
windows下C#定時(shí)管理器框架Task.MainForm詳解
這篇文章主要為大家詳細(xì)介紹了windows下C#定時(shí)管理器框架Task.MainForm的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
C#使用泛型隊(duì)列Queue實(shí)現(xiàn)生產(chǎn)消費(fèi)模式
這篇文章介紹了C#使用泛型隊(duì)列Queue實(shí)現(xiàn)生產(chǎn)消費(fèi)模式的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-10-10
WPF實(shí)現(xiàn)自帶觸控鍵盤(pán)的文本框
這篇文章實(shí)現(xiàn)了WPF自帶觸控鍵盤(pán)的文本框,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-10-10
C#實(shí)現(xiàn)獲取系統(tǒng)目錄并以Tree樹(shù)叉顯示的方法
這篇文章主要介紹了C#實(shí)現(xiàn)獲取系統(tǒng)目錄并以Tree樹(shù)叉顯示的方法,可以加深讀者對(duì)于C#下數(shù)據(jù)結(jié)構(gòu)實(shí)現(xiàn)方法的認(rèn)識(shí),需要的朋友可以參考下2014-07-07
C# 通過(guò)同步和異步實(shí)現(xiàn)優(yōu)化做早餐的時(shí)間
本文以一個(gè)簡(jiǎn)單的小例子—如何做一頓早餐及如何優(yōu)化做早餐的時(shí)間來(lái)讓大家具體了解一下同步和異步方法的區(qū)別,需要的朋友可以參考一下2021-12-12
VS2015為console.readkey添加代碼片段的方法
這篇文章主要介紹了VS2015為console.readkey添加代碼片段的方法,需要的朋友可以參考下2016-12-12

