[C#] C#中异步发送邮件代码 →→→→→进入此内容的聊天室

来自 , 2019-04-24, 写在 C#, 查看 102 次.
URL http://www.code666.cn/view/8c5ebe83
  1. MailMessage m = new MailMessage
  2.    ("item@sharejs.com",
  3.     "raja@sharejs.com",
  4.     "This is the subject for the authorized email.",
  5.     "This is the body of the authorized mail!...");
  6.  
  7. // Send the message using authorization
  8. SmtpClient client = new SmtpClient("smtp.sharejs.com");
  9. client.Credentials = new NetworkCredential("user", "password");
  10. client.EnableSsl = true;
  11.  
  12. // Add the event handler
  13. client.SendCompleted += new SendCompletedEventHandler(mail_SendCompleted);
  14.  
  15. // Send the message asynchronously
  16. client.SendAsync(m, null);
  17.  
  18. // To Cancel the send
  19. //client.SendAsyncCancel();
  20. void mail_SendCompleted(object sender, AsyncCompletedEventArgs e)
  21. {
  22.     if (e.Cancelled)
  23.         Console.WriteLine("Message cancelled");
  24.     else if (e.Error != null)
  25.         Console.WriteLine("Error: " + e.Error.ToString());
  26.     else
  27.         Console.WriteLine("Message sent");
  28. }
  29. //csharp/7762

回复 "C#中异步发送邮件代码"

这儿你可以回复上面这条便签

captcha