C#简单发送email的方法
作者:lele
这篇文章主要介绍了C#简单发送email的方法,涉及C#发送Email的相关技巧,非常具有实用价值,需要的朋友可以参考下
本文实例讲述了C#简单发送email的方法。分享给大家供大家参考。具体实现方法如下:
#region 邮件发送 /// <summary> /// 发送邮件支持HTML格式 先引用System.Net.Mail; /// </summary> /// <param name="MailFrom">发送人Email 如demo@126.com</param> /// <param name="MailServer">邮件服务器 如mail.126.com</param> /// <param name="MailUserName">登陆用户名 如demo@126.com</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#程序设计有所帮助。