sending mail through smtp
-
i am sending mail through smtp.it is working fine but problem is that when i refresh the page mail again be send.i don't want to send mail again when page will refresh.plz help me............. this is my code 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.Net; using System.Net.Mail; using System.Text; using System.IO; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Page.Title = "Contact US"; txt_name.Focus(); lbl_status.Visible = false; } protected void btn_submit_Click(object sender, EventArgs e) { MailMessage mailMsg = new MailMessage("xyz@xyx.in","abc@abc.in"); string name = txt_name.Text.Trim(); string address = txt_add.Text.Trim(); string telnor = txt_telcr.Text.Trim() + "-" + txt_telnr.Text.Trim(); string telnoo = txt_telco.Text.Trim() + "-" + txt_telno.Text.Trim(); string faxno = txt_faxn.Text.Trim(); string mobileno = txt_mobile.Text.Trim(); string typeofwork = rdo_type.Text.Trim(); string query = list_query.Text.Trim(); string Email = Emailid.Text.Trim(); if (Email == "") { Email = "dummyforcheck@in.com"; } mailMsg.Subject = name + " wants to contact us"; mailMsg.IsBodyHtml = true; MailMessage mailMsgUser = new MailMessage("xyx@xyz.in", Email); mailMsgUser.Subject =" Yoyr mail has been recived"; mailMsgUser.IsBodyHtml = true; mailMsg.Body = "<b> Name :" + name + "<br/><b>Address :" + address + "<br/><b>Phone Number(R) :" + telnor + "<br/><b>Phone Number(O) :" + telnoo + "<br/><b>Fax Number :" + faxno + "<br/><b>Mobile Number :" + mobileno + "<br/><b>Mobile Number :" + Email + "<br/><b>Type Of Work :" + typeofwork + "<br/><b>Query :" + query; mailMsgUser.Body = "<b> Esteemed <br/><b> Dear </b>" + name + "<br/><br/><span style='margin-left:50px'> Thanks for contacting us. Our sales executive will contact you shoon.</span><br/><br/><br/><b>Thank you<br/>Royal Village Team.";
-
i am sending mail through smtp.it is working fine but problem is that when i refresh the page mail again be send.i don't want to send mail again when page will refresh.plz help me............. this is my code 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.Net; using System.Net.Mail; using System.Text; using System.IO; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Page.Title = "Contact US"; txt_name.Focus(); lbl_status.Visible = false; } protected void btn_submit_Click(object sender, EventArgs e) { MailMessage mailMsg = new MailMessage("xyz@xyx.in","abc@abc.in"); string name = txt_name.Text.Trim(); string address = txt_add.Text.Trim(); string telnor = txt_telcr.Text.Trim() + "-" + txt_telnr.Text.Trim(); string telnoo = txt_telco.Text.Trim() + "-" + txt_telno.Text.Trim(); string faxno = txt_faxn.Text.Trim(); string mobileno = txt_mobile.Text.Trim(); string typeofwork = rdo_type.Text.Trim(); string query = list_query.Text.Trim(); string Email = Emailid.Text.Trim(); if (Email == "") { Email = "dummyforcheck@in.com"; } mailMsg.Subject = name + " wants to contact us"; mailMsg.IsBodyHtml = true; MailMessage mailMsgUser = new MailMessage("xyx@xyz.in", Email); mailMsgUser.Subject =" Yoyr mail has been recived"; mailMsgUser.IsBodyHtml = true; mailMsg.Body = "<b> Name :" + name + "<br/><b>Address :" + address + "<br/><b>Phone Number(R) :" + telnor + "<br/><b>Phone Number(O) :" + telnoo + "<br/><b>Fax Number :" + faxno + "<br/><b>Mobile Number :" + mobileno + "<br/><b>Mobile Number :" + Email + "<br/><b>Type Of Work :" + typeofwork + "<br/><b>Query :" + query; mailMsgUser.Body = "<b> Esteemed <br/><b> Dear </b>" + name + "<br/><br/><span style='margin-left:50px'> Thanks for contacting us. Our sales executive will contact you shoon.</span><br/><br/><br/><b>Thank you<br/>Royal Village Team.";
-
Sorry, but are you sure this is on click event? because if you send email through on click event it should'nt run on page load. unless this is onPrerender event. I guess so...
Sorry, but are you sure this is on click event? because if you send email through on click event it should'nt run on page load. unless this is onPrerender event. I guess so... yes i am sure that this is on click event. it is working correctly. only problem is that after send mail when i refresh page it will again send the mail.
-
i am sending mail through smtp.it is working fine but problem is that when i refresh the page mail again be send.i don't want to send mail again when page will refresh.plz help me............. this is my code 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.Net; using System.Net.Mail; using System.Text; using System.IO; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Page.Title = "Contact US"; txt_name.Focus(); lbl_status.Visible = false; } protected void btn_submit_Click(object sender, EventArgs e) { MailMessage mailMsg = new MailMessage("xyz@xyx.in","abc@abc.in"); string name = txt_name.Text.Trim(); string address = txt_add.Text.Trim(); string telnor = txt_telcr.Text.Trim() + "-" + txt_telnr.Text.Trim(); string telnoo = txt_telco.Text.Trim() + "-" + txt_telno.Text.Trim(); string faxno = txt_faxn.Text.Trim(); string mobileno = txt_mobile.Text.Trim(); string typeofwork = rdo_type.Text.Trim(); string query = list_query.Text.Trim(); string Email = Emailid.Text.Trim(); if (Email == "") { Email = "dummyforcheck@in.com"; } mailMsg.Subject = name + " wants to contact us"; mailMsg.IsBodyHtml = true; MailMessage mailMsgUser = new MailMessage("xyx@xyz.in", Email); mailMsgUser.Subject =" Yoyr mail has been recived"; mailMsgUser.IsBodyHtml = true; mailMsg.Body = "<b> Name :" + name + "<br/><b>Address :" + address + "<br/><b>Phone Number(R) :" + telnor + "<br/><b>Phone Number(O) :" + telnoo + "<br/><b>Fax Number :" + faxno + "<br/><b>Mobile Number :" + mobileno + "<br/><b>Mobile Number :" + Email + "<br/><b>Type Of Work :" + typeofwork + "<br/><b>Query :" + query; mailMsgUser.Body = "<b> Esteemed <br/><b> Dear </b>" + name + "<br/><br/><span style='margin-left:50px'> Thanks for contacting us. Our sales executive will contact you shoon.</span><br/><br/><br/><b>Thank you<br/>Royal Village Team.";
What exactly do you mean by "refresh"? If you mean you are hitting F5, that reloads the page exactly the same way you got to it including posted form values. That means clicking a button which does a postback and then hitting F5 causes the same exact postback as happened from the button. You could always add a hidden field on the page and in your button click check for a certain value and if that value is there don't send the message.
-
What exactly do you mean by "refresh"? If you mean you are hitting F5, that reloads the page exactly the same way you got to it including posted form values. That means clicking a button which does a postback and then hitting F5 causes the same exact postback as happened from the button. You could always add a hidden field on the page and in your button click check for a certain value and if that value is there don't send the message.
or use...
private void BtnSend_Click(... etc)
{
if (!IsPostBack)
{
//Your mail send code
}//end if (!IsPostBack)
}//End BtnSend_Click:-D ... but anyway your problem is strange! i haven't seen any 'sending-mail on postback' problem! :confused: ok I hope it helps! good luck! :laugh:
-
or use...
private void BtnSend_Click(... etc)
{
if (!IsPostBack)
{
//Your mail send code
}//end if (!IsPostBack)
}//End BtnSend_Click:-D ... but anyway your problem is strange! i haven't seen any 'sending-mail on postback' problem! :confused: ok I hope it helps! good luck! :laugh: