Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. sending mail through smtp

sending mail through smtp

Scheduled Pinned Locked Moved ASP.NET
helpcsharpdatabasecomdesign
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amitamit099
    wrote on last edited by
    #1

    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.";

    L T 2 Replies Last reply
    0
    • A amitamit099

      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.";

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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...

      A 1 Reply Last reply
      0
      • L Lost User

        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...

        A Offline
        A Offline
        amitamit099
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A amitamit099

          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.";

          T Offline
          T Offline
          T M Gray
          wrote on last edited by
          #4

          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.

          P 1 Reply Last reply
          0
          • T T M Gray

            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.

            P Offline
            P Offline
            PunkIsNotDead
            wrote on last edited by
            #5

            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:

            T 1 Reply Last reply
            0
            • P PunkIsNotDead

              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:

              T Offline
              T Offline
              T M Gray
              wrote on last edited by
              #6

              That wouldn't work. A button click event is always a postback. So wrapping the code for sending mail in !IsPostBack defeats the purpose.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups