Click here to Skip to main content
13,869,185 members
Rate this:
Please Sign up or sign in to vote.
See more:
MailMessage msg = new MailMessage();
msg.From = new MailAddress(txtEmail.Text);
msg.IsBodyHtml = true;
msg.Body = "Name : " + txtname.Text + "<br /><br /> Email : " + txtEmail.Text + "<br /><br /> Phone : " + txtmobile.Text + "<br /><br /> Message : " + Txtmessage.Text + "<br>";
msg.Subject = txtSubject.Text;
SmtpClient smtpclient = new SmtpClient();
smtpclient.Host = "";
smtpclient.Port = 587;
smtpclient.Credentials = new System.Net.NetworkCredential("mymailid", "password");
smtpclient.EnableSsl = true;
Label1.Text = "Thanks for contacting us";
txtname.Text = "";
txtEmail.Text = "";
txtSubject.Text = "";
Txtmessage.Text = "";
txtmobile.Text = "";
catch(Exception ex)
Console.WriteLine("{0} Exeception caugh.",ex);

this code of mine working on local host but not working when i put it on server can an one suggest me what to do.

i als like to ask if there is another host(yahoo,my own website etc) then what changes i need to do in my code

What I have tried:

Changed the tag to C#
Updated 19-Sep-18 4:04am
What is "not working", exactly?
shilpamittal15 3-Aug-14 3:00am
mail is not sending with this code when i upload it on server
shilpamittal15 3-Aug-14 3:18am
this whole code is not working the mail is not sending
Marco Bertschi 3-Aug-14 12:03pm
Have you tried to resolve if there is an exception thrown while you run it on the server? Does the server have access to "" (Maybe try to ping it?)?
shilpamittal15 3-Aug-14 13:39pm
there is no exception coming because code is working fine on local host but not doing any thing while uploading.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Check this link!

It worked for other users, if it doesn't work, Check the firewall settings on server!
Try to run this code in a sample snippet, there must be something from the network which might be preventing your code to send an email.
As Marco suggested, try to ping "" from server to check if server allows access to smtp.

Answer of 2nd question:
If you want to use the code for other SMTP Clients, then you can change the SmtpClient settings as SmtpServer name and port. :)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190214.1 | Last Updated 19 Sep 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100