zoukankan      html  css  js  c++  java
  • Send Email

     private string SendEmail(string mailTo, string body, ref int sendresult)
            {
                string errorEmailAddress = ""; 
                SmtpClient smtp = new SmtpClient(_SmtpServer);
                try
                {
    
                    MailMessage message = new MailMessage();
                    message.Priority = MailPriority.High;
                    message.From = new MailAddress(_From);
                    //message.To.Add(mailTo);
                    message.Subject = _Subject;
                    message.Body = body;
                    message.IsBodyHtml = true;
                    message.Bcc.Add(new MailAddress(_Bcc, "", Encoding.Default));
                    SetToMailAddress(mailTo, message, ref errorEmailAddress);
                    if (message.To.Count > 0)
                    {
                        smtp.Send(message);
                        sendresult = 1;
                    } 
                    smtp.Dispose();
                    return string.IsNullOrEmpty(errorEmailAddress) ? string.Empty : ("Error email address:"+errorEmailAddress);
                }
                catch (Exception e)
                {
                    smtp.Dispose(); 
                    return e.InnerException.Message + (string.IsNullOrEmpty(errorEmailAddress) ? "" : (" Error email address: " + errorEmailAddress)); 
                }
            }
            private static void SetToMailAddress(string toMailAddress, MailMessage message, ref string errorEmailAddress)
            {
                string[] addes = toMailAddress.Split(';').ToArray();
                foreach (string s in addes)
                {
                    if (Regex.IsMatch(s, @"w+([-+.']w+)*@w+([-.]w+)*.w+([-.]w+)*"))
                    {
                        message.To.Add(new MailAddress(s.Trim(), "", Encoding.Default));
                    }
                    else
                    { errorEmailAddress += s + ";"; }
                }
            } 
  • 相关阅读:
    windows 设置nginx开机自启动
    vue js中解决二进制转图片显示问题
    oracle 各种问题
    Nginx安装及配置详解包括windows linux 环境
    AOP-切面是如何织入到目标对象中的
    AOP-通知-笔记
    AOP-方法拦截器-笔记
    JdkDynamicAopProxy-笔记
    Joinpoint继承体系-笔记
    AOP-Pointcut-笔记
  • 原文地址:https://www.cnblogs.com/muxueyuan/p/6868271.html
Copyright © 2011-2022 走看看