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ì)方打開郵件可獲得提醒
- C# SendMail發(fā)送郵件功能實(shí)現(xiàn)
- C#使用windows服務(wù)發(fā)送郵件
- C#編程實(shí)現(xiàn)發(fā)送郵件的方法(可添加附件)
- C#編寫發(fā)送郵件組件
- C#使用自帶的email組件發(fā)送郵件的方法
- C#實(shí)現(xiàn)發(fā)送郵件的三種方法
- C# SMTP發(fā)送郵件的示例
相關(guān)文章
.NET使用IResourceMonitor實(shí)現(xiàn)獲取資源信息
在 Microsoft.Extensions.Diagnostics.ResourceMonitoring 包提供了一系列定制 API,專用于監(jiān)視 .NET 應(yīng)用程序的資源利用率,本文將利用IResourceMonitor來實(shí)現(xiàn)獲取資源狀態(tài)信息,感興趣的可以了解下2024-01-01
C#實(shí)現(xiàn)圖像選擇驗(yàn)證碼的示例代碼
為了防止網(wǎng)站被非法登陸,網(wǎng)站一般通過驗(yàn)證碼的方式,防止黑客用軟件非法登陸,本文主要介紹了C#實(shí)現(xiàn)圖像選擇驗(yàn)證碼的示例代碼,具有一定的參考價(jià)值,感興趣的可以了解一下2023-08-08
C#多線程學(xué)習(xí)之(一)多線程的相關(guān)概念分析
這篇文章主要介紹了C#多線程學(xué)習(xí)之多線程的相關(guān)概念,涉及C#中多線程的相關(guān)概念與使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04
C#用websocket實(shí)現(xiàn)簡易聊天功能(客戶端)
這篇文章主要為大家詳細(xì)介紹了C#用websocket實(shí)現(xiàn)簡易聊天功能,客戶端方向,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
Linq利用Distinct去除重復(fù)項(xiàng)問題(可自己指定)
這篇文章主要介紹了Linq利用Distinct去除重復(fù)項(xiàng)問題(可自己指定),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01

