C#发送email C#简单发送email的方法
lele 人气:0想了解C#简单发送email的方法的相关内容吗,lele在本文为您仔细讲解C#发送email的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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#程序设计有所帮助。
加载全部内容