Click here to Skip to main content
15,885,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
can we use gmail smtp in live website to send mail(feedback) from contactus form to the owner of the website, is it possible?



mail is send to the desire email id from local host from feedback form.
but problem occur when the same project uploaded to the live web server.
on clicking the submit button in the feedback form nothing happen.

what and where is the problem i can't get that?
because this application behave normal at local-host.

please guide me regarding this problem.

this line is appended with the url while clicking on submit button.

__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKMTk2Njc5ODE2N2RkEGPdgAflCjv7N%2Fj8z04OHUSWDag%3D&__EVENTVALIDATION=%2FwEWBgLzi4feDwK0w7i7DQK9w4QnAqHo7y4C9oCMmQwCro6e7AMCSNU4FMIyaDwIGsIYTXrxUJrXnQ%3D%3D&ctl00%24ContentPlaceHolder1%24txtName=balwant&ctl00%24ContentPlaceHolder1%24txtMail=balwant.mnd%40gmail.com&ctl00%24ContentPlaceHolder1%24txtFeed=testing&ctl00%24ContentPlaceHolder1%24btsubmit=Submit



my code for sending email is as follow:
C#
protected void btSubmit_Click(object sender, EventArgs e)
    {
        try
        {

            SmtpClient smtpClient = new SmtpClient();
            MailMessage objMail = new MailMessage();
            //From Address will be assigned from the e-mail specified in the From TextField You can also give the code given below.
            MailAddress objMail_fromaddress = new MailAddress(txtMail.Text);
            MailAddress objMail_toaddress = new MailAddress("mymail@gmail.com");
            objMail.IsBodyHtml = true;
            //Assigning From address to the MailMessage class
            objMail.From = objMail_fromaddress;
            //Assigning To address to the MailMessage class as a collection
            objMail.To.Add(objMail_toaddress);
            objMail.Subject = "Feedback from" + txtName.Text + " to us from Contact us Form";
            objMail.Body = "Message from" + txtName.Text + "as comments:-" + txtComments.Text + "<br><br><br>" + "Address:" + txtAddress.Text + "<br>Mobile no:" + txtTel.Text;
            objMail.Priority = MailPriority.High;
            smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 587
            smtpClient.Credentials = new  System.Net.NetworkCredential("mymail@gmail.com", "1239807643");
            smtpClient.EnableSsl = true;
            smtpClient.Send(objMail);
            Label1.Visible = true;
            Label1.Text = "your feedback is submitted successfully.";
        }
        catch (Exception ex)
        {

            Label1.Visible = true;
            Label1.Text = "something went wrong!, Please Try Again." + ex.Message;
        }
Posted
Updated 1-Feb-11 4:07am
v5
Comments
R. Giskard Reventlov 24-Jan-11 5:24am    
Are you pointing at the correct SMTP server?
michaelschmitt 24-Jan-11 5:27am    
I suggest you implement some kind of logging mechanism. There may be a bug in your code, you may have misconfigured the mailserver credentials on your webserver or whatever.
Balwant.mnd 27-Jan-11 0:34am    
some great ans plz
Rupa1 1-Feb-11 8:01am    
can You paste your coding here
Balwant.mnd 2-Feb-11 1:19am    
plz check the code

It can be because of various reasons. You need to look at them one by one.
Is the port open? Firewall permissions in place?
Further make sure you have configured SMTP configuration in Web.Config:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>

If needed, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]
 
Share this answer
 
Comments
Balwant.mnd 16-Apr-11 2:15am    
hi,

how to used the web.config setting incs file of asp.net page to send email.
please explain.
Sandeep Mewara 16-Apr-11 10:26am    
Everything needed was shared. You need to put this config in your config file, probably under system.web tag.

Video tutorial was also shared, did you went through?
You need to configure SMTP on server to make this work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900