C#簡略發送email的辦法。本站提示廣大學習愛好者:(C#簡略發送email的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#簡略發送email的辦法正文
本文實例講述了C#簡略發送email的辦法。分享給年夜家供年夜家參考。詳細完成辦法以下:
#region 郵件發送 /// <summary> /// 發送郵件支撐HTML格局 先援用System.Net.Mail; /// </summary> /// <param name="MailFrom">發送人Email 如[email protected]</param> /// <param name="MailServer">郵件辦事器 如mail.126.com</param> /// <param name="MailUserName">上岸用戶名 如[email protected]</param> /// <param name="MailPassword">上岸暗碼 如123456</param> /// <param name="mailto">收件人郵箱</param> /// <param name="title">郵件題目</param> /// <param name="msg">郵件注釋</param> /// <returns>勝利 true; 掉敗 false</returns> public static bool SendSmtpEmail(string MailFrom,string MailServer,string MailUserName,string MailPassword,string mailto,string title,string msg) { var client = new SmtpClient(); client.Host = MailServer; client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(MailUserName, MailPassword); client.DeliveryMethod = SmtpDeliveryMethod.Network; System.Net.Mail.MailMessage message = new MailMessage(MailFrom, mailto); message.Subject = title; message.Body = msg; message.SubjectEncoding = System.Text.Encoding.UTF8; message.BodyEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = true; message.Priority = MailPriority.High; message.IsBodyHtml = true; try { client.Send(message); return true; } catch { return false; } } #endregion
願望本文所述對年夜家的C#法式設計有所贊助。