DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   ASP.NET (http://www.daniweb.com/forums/forum18.html)
-   -   sending email (http://www.daniweb.com/forums/thread78637.html)

sibotho May 18th, 2007 3:58 am
sending email
 
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.






NET-Developer May 18th, 2007 8:05 am
Re: sending email
 
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.

sibotho May 18th, 2007 8:59 am
Re: sending email
 
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();
}

NET-Developer May 18th, 2007 9:15 am
Re: sending email
 
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.


All times are GMT -4. The time now is 8:14 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC