2013-08-20 70 views
1

我有一個頁面,允許用戶發送電子郵件我只想顯示一條消息警報給用戶,如果電子郵件成功發送或沒有按鈕點擊事件是否有一種方法,我可以檢查電子郵件是否已成功發送?並在電子郵件發送後,我可以簡單地使用'textbox.text =「」'來清除頁面上的控件?關於按鈕點擊事件的Asp.net電子郵件驗證

下面是如果你正在使用System.Net.Mail你可以試試這個對按鈕單擊事件

protected void btnsendEmail_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      char[] split = { ';' };    
      foreach (string mailAdd in txtemailAdd.Text.Split(split)) 
      { 
       sendMail(mailAdd); 
      } 
     } 
     catch (Exception ex) 
     { 

     } 
} 
+0

http://www.ultradevelopers.net/Blog/16 –

+0

您還應該使用[post/redirect/get](http://en.wikipedia.org/wiki/Post/Redirect/Get)模式,以避免用戶刷新頁面並重新發送電子郵件。即在您重定向到的**新**頁面上顯示您的conf信息。 –

回答

0

代碼: -

message.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.OnSuccess; 
0

讓你的函數發送電子郵件「的sendmail(mailAdd); 「回報取決於如果電子郵件發送或不併顯示信息

0

真的還是假的你可以嘗試這樣的: -

protected void btnsendEmail_Click(object sender, EventArgs e) 
    { 
     try 
     { 


      char[] split = { ';' }; 

      foreach (string mailAdd in txtemailAdd.Text.Split(split)) 
      { 
       sendMail(mailAdd); 


      } 
      // mail is successfully sent :- 
      Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Msg", "alert('Mail sent successfully')", true); 
     } 
     catch (Exception ex) 
     { 
        // mail is not successfully sent :- 
      Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Msg", "alert('Mail not sent successfully')", true); 
     } 
}