• 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;
            }
    
  • 相关阅读:
    ASP.NET中POST提交数据并跳转页面
    kindeditor编辑器图片水印
    jquery live hover绑定方法
    ASP.NET MVC实现多个按钮提交事件
    Asp.Net时间戳与时间互转
    Django-管理站点重写admin模板
    Pycharm快捷键整理(Mac)
    Python 调用datetime或者time获取时间的时候以及时间转换,最好设置一下时区 否则会出现相差8个小时的情况
    django中使用原生sql
    [django]用日期来查询datetime类型字段
  • 原文地址:https://www.cnblogs.com/apeng/p/5431251.html
Copyright © 2020-2023  润新知