在学习闲暇时间,将写内容过程经常用的内容段做个收藏,下面的内容是关于C#中异步发送邮件的内容,应该能对各位朋友有好处。
MailMessage m = new MailMessage
"This is the subject for the authorized email.",
"This is the body of the authorized mail!...");
client.Credentials = new NetworkCredential("user", "password");
client.EnableSsl = true;
client.SendCompleted += new SendCompletedEventHandler(mail_SendCompleted);
client.SendAsync(m, null);
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");
}