• 群发邮件


    using System.Net.Mail;
    private bool SendEmail(string astrEachEmail, string bt, string nr)
        {
            string strSendEmail = ConfigurationManager.AppSettings["fromMail"];
            string strUserName = ConfigurationManager.AppSettings["mailAccount"];
            string strPassWord = AllTableHelp.jieMi(ConfigurationManager.AppSettings["mailPWD"]);
            string strRecieveEMail = astrEachEmail;
            string strSubject = bt;
            string strBody = nr;
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
            msg.To.Add(strRecieveEMail);
            ////附件处理
            //if (txtAttachment.Text.Trim().Length > 0)
            //{
            // string FileName = @txtAttachment.Text.Trim();
            // System.Net.Mail.Attachment pAttachment = new Attachment(FileName);
            // msg.Attachments.Add(pAttachment);
            //}
            msg.From = new MailAddress(strSendEmail);
            msg.Subject = strSubject;//邮件标题 
            msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码 
            msg.Body = strBody;//邮件内容 
            msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码 
            msg.IsBodyHtml = false;//是否是HTML邮件 
            msg.Priority = MailPriority.High;//邮件优先级 
    
            SmtpClient client = new SmtpClient();
            client.Host = ConfigurationManager.AppSettings["MailHost"];//为邮件服务器设置
            System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential(strUserName, strPassWord);
            client.Credentials = basicAuthenticationInfo;
    
            object userState = msg;
            try
            {
                client.Send(msg);
                //client.SendAsync(msg, userState);//简单一点儿可以client.Send(msg); 
                return true;
            }
            catch
            {
                return false;
            }
        }
  • 相关阅读:
    django报错问题解决
    django2-项目实战
    django1-环境搭建与开始
    python学习-模块与包(九)
    逆水行舟,不进则退
    待学习规划内容
    越来越强大法则
    windows下安装scoop
    pytest+allure生成测试报告
    Angular vscode 调试
  • 原文地址:https://www.cnblogs.com/daixingqing/p/2768429.html
Copyright © 2020-2023  润新知