国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

C#中使用System.Web.Mail.MailMessage類無法CC多人的問題

2019-11-17 02:24:48
字體:
來源:轉載
供稿:網友
C#中使用System.Web.Mail.MailMessage類無法CC多人的問題

從.NET 2.0 開始,引入了一個新的類,System.Net.Mail.MailMessage。該類用來取代 .NET 1.1 時代System.Web.Mail.MailMessage類。System.Net.Mail.MailMessage 類用于指定一個郵件,另外一個類 System.Net.Mail.SmtpClient 則用來設置 SMTP,然后發送郵件。由于目前 SMTP 都需要進行身份驗證,有的還需要 SSL(比如Gmail),所以設置的屬性稍微多一些。代碼片斷如下:

using System.Net.Mail;MailMessage mailMsg = new MailMessage(); mailMsg.From = new MailAddress("你的email地址"); mailMsg.To.Add("接收人1的email地址"); mailMsg.To.Add("接收人2的email地址"); mailMsg.Subject = "郵件主題"; mailMsg.Body = "郵件主體內容"; mailMsg.BodyEncoding = Encoding.UTF8; mailMsg.IsBodyHtml = false; mailMsg.PRiority = MailPriority.High; SmtpClient smtp = new SmtpClient(); // 提供身份驗證的用戶名和密碼 // 網易郵件用戶可能為:username passWord // Gmail 用戶可能為:username@gmail.com password smtp.Credentials = new NetworkCredential("用戶名", "密碼");smtp.Port = 25; // Gmail 使用 465 和 587 端口 smtp.Host = "SMTP 服務器地址"; // 如 smtp.163.com, smtp.gmail.com smtp.EnableSsl = false; // 如果使用GMail,則需要設置為true smtp.SendCompleted += new SendCompletedEventHandler(SendMailCompleted); try {     smtp.SendAsync(mailMsg, mailMsg); } catch (SmtpException ex) {     Console.WriteLine(ex.ToString()); } ... void SendMailCompleted(object sender, AsyncCompletedEventArgs e) {     MailMessage mailMsg = (MailMessage)e.UserState;     string subject = mailMsg.Subject;     if (e.Cancelled) // 郵件被取消     { Console.WriteLine(subject + " 被取消。");     }     if (e.Error != null)     {         Console.WriteLine("錯誤:" + e.Error.ToString());     }     else     {         Console.WriteLine("發送完成。");     } }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 九寨沟县| 南丹县| 桓仁| 霍林郭勒市| 信丰县| 连南| 广水市| 永德县| 上栗县| 博湖县| 上杭县| 云龙县| 游戏| 白朗县| 临江市| 连云港市| 福州市| 灵石县| 偏关县| 景德镇市| 宜黄县| 雷波县| 上杭县| 高州市| 镇沅| 通州市| 晋城| 深圳市| 大理市| 涟源市| 大冶市| 永兴县| 建宁县| 灵寿县| 项城市| 晋中市| 沙河市| 温泉县| 富源县| 桓仁| 肇庆市|