send Mail

namespace tMail
{
 /// <summary>
 /// WebForm1 的摘要說明。
 /// </summary>
 public class WebForm1 : System.Web.UI.Page
 {

         MailMessage _MailMessage=new MailMessage();
  string UserName="drk928";
  string PassWord="horse";
  string EmailServer="smtp.163.com";
  protected System.Web.UI.WebControls.Button Button1;
  string EmailTo="[email protected]";
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此處放置用戶代碼以初始化頁面
   
   
  }
  private bool sendvalid()
  {
       
   this._MailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"]  = 2;
   
   if (this.UserName != null && this.PassWord != null)
   {
    this._MailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
    this._MailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = this.UserName;
    this._MailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = this.PassWord;
   }
   this._MailMessage.To =this.EmailTo;
   SmtpMail.SmtpServer =this.EmailServer;
   try
   {
    SmtpMail.Send(this._MailMessage);
    
   }
   catch(Exception ex)
   {
    //this.WriteLogTxt("ErrorMessage:"+ex.Message,false);
    return false;
   }
   return true;
  
  }
  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN:該調用是 ASP.NET Web 窗體設計器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
  /// 此方法的內容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.Button1.Click += new System.EventHandler(this.Button1_Click);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  private void Button1_Click(object sender, System.EventArgs e)
  {
   bool pd=sendvalid();
   Response.Write(pd);
  }
 }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章