Unable to send mail over smtp server, as the 'operation timeout' error occurs
13,179
Solution 1
Please try with port number 587.
Solution 2
Placing the line: smtp.UseDefaultCredentials = false;
above the line: smtp.Credentials = new NetworkCredential("[email protected]", "password");
and using the port number 587 solves the problem.
Thanks everyone, for your contributions.!
Author by
user3391912
Updated on June 04, 2022Comments
-
user3391912 almost 2 years
Unable to send mail over smtp server, as the 'operation timeout' error occurs. I have tried almost all the methods given on this website, have tried using another port number and also the client other than gmail, I wonder what the problem is. Following is the attached code segment.
using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net.Security; using System.Net.Mail; using System.Net; public partial class home : System.Web.UI.Page { SmtpClient smtp = new SmtpClient(); MailMessage newMail = new MailMessage(); protected void Page_Load(object sender, EventArgs e) { smtp.Host = "smtp.gmail.com"; smtp.Port = 465; smtp.Credentials = new NetworkCredential("[email protected]", "password"); smtp.UseDefaultCredentials = false; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.EnableSsl = true; newMail.From = new MailAddress("[email protected]"); newMail.Priority = MailPriority.High; } protected void Button_send_Click(object sender, EventArgs e) { try { newMail.To.Add(new MailAddress(TextBox_to.Text)); newMail.Subject = TextBox_sub.Text; newMail.Body = TextBox_mail.Text; smtp.Send(newMail); Label_msg.Text = "Message Sent Successfully."; Label_msg.Visible = true; } catch (Exception ex) { Label_msg.Text = "Message not sent <br/>" + ex.Message; } } }
-
user3391912 about 10 yearsI tried using port number 587, as I have already mentioned that I used different port number too. But it still doesn't works. It gets timed out. My internet connection is also fast enough, so I don't know why it gets timed out.
-
Saad Alothman over 9 yearsUnbelievable ! when i change to Google Apps account it did not work until i did this!! Thanks Alot