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

  • 相关阅读:
    MT【48】分式连加形式下求不等式解集的区间长度
    MT【47】求一道分式的最值
    MT【46】不动点,稳定点几何直观
    MT【45】抛物线外一点作抛物线的切线(尺规作图题)
    MT【44】抛物线不常见性质3
    MT【43】抛物线不常见性质2.
    MT【42】抛物线不常见性质1.
    MT【41】利用不等式妙消参数
    MT【40】一道联赛二试题
    MT【39】构造二次函数证明
  • 原文地址:https://www.cnblogs.com/changlin/p/1839391.html
Copyright © 2011-2022 走看看