2013-08-20 69 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); 
     } 
}