首页 > 编程 > C# > 正文

C#简单发送email的方法

2020-01-24 01:54:24
字体:
来源:转载
供稿:网友

本文实例讲述了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#程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表