Hi all

I have been trying to send email from my asp.net website using c#. the code runs without any errors, but when i click the send button i get this error.

/*System.Net.Mail.SmtpException: Failure sending mail.---> System.Net.WebException: Unable to connect to remote server -->System.net.sockets.socketException: a connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
at System.Net.Sockets.Socket.EndConnect(IAsyscResult asyncResult)*/
------------------------------------------------------------------

I heard that McAffee OAS blocks emails from going out but i have disabled it in my computer. Can you please help in eliminating this error.

Check, if your mail client is created in this way ?

System.Net.Mail.SmtpClient mailClient = new SmtpClient("your.smtp.server", 25);
System.Net.NetworkCredential nc = new System.Net.NetworkCredential("YourLogin", "YourPassword");
mailClient.Credentials = nc;

And also check address of your SMTP server, login and password, if they are all correct. Or there may be also problems at server side.

here is the code i used

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add(emailAddTextBox.Text);
message.Subject = "Testing";
message.From = new System.Net.Mail.MailAddress("myusername@gmail.com");
message.Body = "Just Testing";
 
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com",25);

 
SmtpClient client = new SmtpClient();
smtp.Credentials = new System.Net.NetworkCredential("myusername", "mypassword");
smtp.Port = 587; 
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;

 
try
{
smtp.Send(message);
}
catch (Exception exmail)
{
flightNameLabel.Text = "The email cannot be sent" + exmail.ToString();
}

But are you sure that smtp.Port must be 587 but not 25 ? Usually SMTP port is 25 (that is why I have prescribed 25 in SmtpClient constructor). If it is 587, then replace 25 into 587 in that line. Try also with smtp.EnableSsi = false.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.