码迷,mamicode.com
首页 > 其他好文 > 详细

邮箱验证 (给邮箱发送验证信息)

时间:2018-05-16 16:34:31      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:服务   odi   tp服务器   login   net   .net   优先   empty   except   

#region
/// <summary>
/// 发送邮件验证码
/// </summary>
/// <param name="loginName"></param>
/// string smtpServer = "smtp.exmail.qq.com" + ""; //服务器地址
/// string uName = "发送方账号";
/// string uPwd = "发送方密码";
/// string fromMail = "发送方账号";
///  string toMail = “接受方账号”;
/// string subj = "标题";              
/// string bodys = "内容:
public static void SimpleSendEmail(string smtpServer, string uName, string uPwd, string fromMail, string toMail, string subj, string bodys) { try { //构造一个发件人地址对象 MailAddress from = new MailAddress(fromMail); //构造一个Email的Message对象 MailMessage message = new MailMessage(); //添加邮件主题和内容 message.From = from; string[] toEmailList = MySplit(toMail); for (int i = 0; i < toEmailList.Length; i++) { if (!string.IsNullOrEmpty(toEmailList[i])) { message.To.Add(toEmailList[i]); } } message.Subject = subj; message.SubjectEncoding = Encoding.UTF8; message.Body = bodys; message.BodyEncoding = Encoding.UTF8; message.IsBodyHtml = true; message.Priority = MailPriority.Normal;//优先级 //确定smtp服务器地址。实例化一个Smtp客户端 SmtpClient client = new SmtpClient(); client.Host = smtpServer; client.UseDefaultCredentials = true; //设置邮件的信息 client.DeliveryMethod = SmtpDeliveryMethod.Network; //用户登陆信息 System.Net.NetworkCredential myCredentials = new System.Net.NetworkCredential(uName, uPwd); client.Credentials = myCredentials; //发送邮件 client.Send(message); } catch (Exception e) { throw e; } } private static string[] MySplit(string a) { return a.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); } #endregion SendEmail

 

邮箱验证 (给邮箱发送验证信息)

标签:服务   odi   tp服务器   login   net   .net   优先   empty   except   

原文地址:https://www.cnblogs.com/LiYi-Dao/p/9046439.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!