I created a registration form in the asp.net and everything is working fine, then, I added the following code to be able to send an email to the user and the host, it is still working but I didn't received any email, do you know what is the problem with my code?
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SmtpClient client = new SmtpClient("smtp.gmail.com",587);
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("##########", "###########");
MailMessage mailmsg = new MailMessage();
mailmsg.To.Add(TxtEmail.Text);
mailmsg.From = new MailAddress("################");
mailmsg.Subject = "The email is confirmed";
mailmsg.Body = "Dear "+ TxtName.Text + ",\n\nyou have been registred successfully";
client.Send(mailmsg);
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('message has been sent successfully');", true);
MailMessage mailmsg2 = new MailMessage();
mailmsg2.To.Add("################");
mailmsg.From = new MailAddress("##############");
mailmsg.Subject = "New user has registred";
mailmsg.Body = "Dear Admin, \n\nthere are a new user registred in the website";
client.Send(mailmsg);
}
catch (Exception ex)
{
Response.Write("Couldn't send email: " + ex.Message);
}
}
I am getting the output:
Couldn't send email: Failure sending mail