send email probleum

Aug 2 2014 1:38 PM
MailMessage msg = new MailMessage();
msg.From = new MailAddress(txtEmail.Text);
msg.To.Add("mymailid");
msg.IsBodyHtml = true;
msg.Body = "<b>Name : </b>" + txtname.Text + "<br/><br/><b> Email : </b>" + txtEmail.Text + "<br/><br/><b> Phone : </b>" + txtmobile.Text + "<br/><br/><b> Message : </b>" + Txtmessage.Text + "<br>";
msg.Subject = txtSubject.Text;
SmtpClient smtpclient = new SmtpClient();
smtpclient.Host = "smtp.gmail.com";
smtpclient.Port = 587;
smtpclient.Credentials = new System.Net.NetworkCredential("mymailid", "password");
smtpclient.EnableSsl = true;
smtpclient.Send(msg);
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. 

Answers (5)