C# 发送邮件

        ///<summary> 发送邮件
        ///</summary>
        ///<param name="title">标题</param>
        ///<param name="Content">内容</param>
        ///<param name="EmailAddress">收件人 【多个地址 ; 分隔】</param>;
        ///<param name="CtoAddress"></param>
        ///<returns></returns>
        public bool SendEmail_New(string title, string Content, string EmailAddress, string CtoAddress)
        {
            bool result = false;
            try
            {
                string smtpHost = "smtp.exmail.qq.com";  //邮箱的代理地址
                int smtpPort = 25;
                string senderEmail = "xxxxx@qq.com";  //邮箱地址
                string recipientEmail = receiverList3;  //配置的收件人
                string subject = title;
                string body = Content;
                SmtpConfig.VerifyAddresses = false;
                MailMessage msg = new MailMessage();
                msg.Charset = "gb2312";
                msg.Subject = subject;
                msg.AddCustomHeader("Disposition-Notification-To", senderEmail);
                msg.Body = body;
                msg.Priority = MailPriority.High;
                EmailAddress ems = new EmailAddress(senderEmail);//发件人
                msg.From = ems;
                List&lt;EmailAddress&gt; lst_receive = new List&lt;EmailAddress&gt;();//收件人
                foreach (var item in EmailAddress.Split(';'))
                {
                    lst_receive.Add(new EmailAddress(item));
                }
                msg.To.AddRange(lst_receive);
                //if (!string.IsNullOrEmpty(fileName))
                //    msg.AddAttachment(fileName);//附件
                List&lt;EmailAddress&gt; lst_cc = new List&lt;EmailAddress&gt;();//抄送
                foreach (var item in CtoAddress.Split(';'))
                {
                    lst_cc.Add(new EmailAddress(item));
                }
                msg.CC.AddRange(lst_cc);//CC可以看到抄送列表,BCC看不到抄送列表
                Smtp smtp = new Smtp(smtpHost, smtpPort);
                smtp.Username = "xxxx@qq.com";  //此处是邮箱地址
                smtp.Password = "******";   //此处是邮箱密码
                smtp.SendMail(msg);
                result = true;
            }
            catch (Exception ex)
            {
                LogHelper.Instance.Log.Info(ex.Message);
                result = false;
            }
            return result;
        }
posted @ 2016-04-25 15:56  阿鹏哥  阅读(184)  评论(0编辑  收藏  举报