zoukankan      html  css  js  c++  java
  • 邮件发送类代码

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Web.Mail;
    namespace BaseProject.Classes.Util
    {
        public class MailManage
        {
            public bool SendMail(string toMail, string subject, string body)
            {
                try
                {
                    string fromMail = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["mailService"] ?? "");
                    MailMessage myMail = new MailMessage();
                    myMail.From = fromMail;
                    myMail.To = toMail;

                    myMail.Subject = subject;
                    myMail.Body = body;
                    myMail.BodyFormat = MailFormat.Html;

                    ////附件
                    //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 MailAttachment(ServerFileName));
                    //}


                    myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
                    myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["mailUser"] ?? "")); //发送方邮件帐户
                    myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["mailPass"] ?? "")); //发送方邮件密码

                    SmtpMail.SmtpServer = "smtp." + fromMail.Substring(fromMail.IndexOf("@") + 1);
                    SmtpMail.Send(myMail);

                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
    }

  • 相关阅读:
    进程与线程
    the art of seo(chapter seven)
    the art of seo(chapter six)
    the art of seo(chapter five)
    the art of seo(chapter four)
    the art of seo(chapter three)
    the art of seo(chapter two)
    the art of seo(chapter one)
    Sentinel Cluster流程分析
    Sentinel Core流程分析
  • 原文地址:https://www.cnblogs.com/bestsaler/p/1835706.html
Copyright © 2011-2022 走看看