标签:服务 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