zoukankan      html  css  js  c++  java
  • 群发邮件

    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;
            }
        }
  • 相关阅读:
    JVM基础和调优(一)
    Jtree(节点的渲染+资源管理器)(2)
    Jtree (节点的渲染+资源管理器)
    jtree(选择框)
    java进阶计划
    SQL优化
    spring 事务管理
    Spring事务配置的五种方式(转)
    spring与数据库之间的配置
    struct2(六) 为表单添加验证
  • 原文地址:https://www.cnblogs.com/daixingqing/p/2768429.html
Copyright © 2011-2022 走看看