群发邮件

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;
        }
    }

 

posted @ 2012-11-13 17:43  一千零一夜  阅读(147)  评论(0编辑  收藏  举报