zoukankan      html  css  js  c++  java
  • asp.net发送邮件

    /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="fromMail">发送人邮箱地址</param>
        /// <param name="fromMailPws">发送人邮箱密码</param>
        /// <param name="fromName">发送人姓名</param>
        /// <param name="toMail">收件人邮箱地址</param>
        /// <param name="ccMail">抄送人邮箱地址</param>
        /// <param name="bccMail">密送人邮箱地址</param>
        /// <param name="subject">邮件标题</param>
        /// <param name="body">邮件内容</param>
        /// <param name="isBodyHtml">是否为HTML格式的内容</param>
        /// <returns></returns>
        private bool SendMail(string fromMail,string fromMailPws,string fromName, string toMail, string ccMail, string bccMail, string subject, string body, bool isBodyHtml)
        {
            try
            {
                MailMessage myMail = new MailMessage();
                myMail.From = new MailAddress(fromMail, fromName, System.Text.Encoding.UTF8);
                myMail.To.Add(toMail);
                myMail.Subject = subject;
                myMail.Body = body;
                myMail.IsBodyHtml = isBodyHtml;
                ////附件
                //  string ServerFileName = "";
                //  if (this.upfile.PostedFile.ContentLength != 0)
                //  {
                //      string upFileName = this.upfile.PostedFile.FileName;
                //      string[] strTemp = upFileName.Split('.');
                //      string upFileExp = strTemp[strTemp.Length - 1].ToString();
                //      ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp);
                //      this.upfile.PostedFile.SaveAs(ServerFileName);
                //      myMail.Attachments.Add(new Attachment(ServerFileName));
                //  }

                 
                  string smtp = "smtp." + fromMail.Substring(fromMail.IndexOf("@") + 1);
                  //域名是否可用
                  string DomainEnabled = Utility.GetAppSettingsValue("DomainEnabled");
                  if (DomainEnabled.ToLower() == "false")
                  smtp = "192.168.1.119";
                  SmtpClient sc = new SmtpClient(smtp);
                  sc.Credentials = new System.Net.NetworkCredential(fromMail, fromMailPws);//邮箱账号与密码
                  sc.Send(myMail);   //发送邮件

                return true;
            }
            catch (Exception e32)
            {
                Response.Write(e32.ToString());
                return false;
            }
        }

  • 相关阅读:
    【已解决】对发现无理数过程的逻辑严谨性的疑惑
    微积分奇观之计算曲线的平均高度
    闲鱼二维码 另外那个号
    联通KD-YUN-811G光猫管理员密码
    人工智能结课作业-BP神经网络/卷积神经网络手写体识别
    人工智能结课作业-遗传算法/粒子群寻优/蚁群算法解决TSP问题
    人工智能结课作业-DFS/BFS/Astar解决八数码问题
    AMD 2020显卡驱动没有切换独立显卡选项
    linux创建文件夹快捷方式
    Ubuntu 18.04 设置开机启动脚本
  • 原文地址:https://www.cnblogs.com/changlin/p/1839391.html
Copyright © 2011-2022 走看看