C# 发送邮件,发送Email,此处以QQ邮箱为例
using System.Text;
using System.Net.Mail;
/// <summary> /// 发送邮件 /// </summary> /// <param name="emailFrom">发件人</param> /// <param name="emailTo">收件人</param> /// <param name="title">标题</param> /// <param name="body">正文</param> /// <param name="password">密码或授权码</param> internal static void SendEmail(string emailFrom, string emailTo, string title, string body, string password) { MailAddress from = new MailAddress(emailFrom); MailMessage message = new MailMessage() { Body = body, IsBodyHtml = true, BodyEncoding = Encoding.UTF8, Subject = title, SubjectEncoding = Encoding.UTF8, From = from, Priority = MailPriority.High }; message.To.Add(emailTo); SmtpClient client = new SmtpClient() { EnableSsl = true, Host = "smtp.qq.com", Port = 587, }; client.Credentials = new System.Net.NetworkCredential(emailFrom, password); try { client.Send(message); } catch { } }
评论前必须登录!
注册