我有一个网站,有一个Contact Us
标签。用户必须填写表格,点击按钮我应该收到用户的邮件。
当我从localhost运行时,它工作正常。但是相同的代码并没有在Godaddy网络服务器中运行。这是我的代码
try
{
MailMessage mailMessage = new MailMessage("From@gmail.com", "To@mydomain.com");
mailMessage.Subject = txtSubject.Text;
string msg = "#Sender Name: " + txtUserName.Text + "#Sender Email ID: " + txtUserEmailId.Text + "#Company Name: " + txtCompanyName.Text + "#Mobile No: " + txtMobileNo.Text + "#Office Telephone No: " + txtOfficeTelephoneNo.Text + "#Office Fax No: " + txtOfficeFaxNo.Text + "#City: " + txtCity.Text + "#Sender Message: " + txtMessage.Text;
string newMsg = msg.Replace("#", "\n");
mailMessage.Body = newMsg;
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
smtpClient.Credentials = new System.Net.NetworkCredential()
{
UserName = "From@gmail.com",
Password = "Password"
};
smtpClient.EnableSsl = true;
smtpClient.Send(mailMessage);
}
catch (Exception ee)
{
Response.Write(ee.Message);
}