Unable to send mail using System.Net.Mail

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am trying to send a mail using the System.Net.Mail namespace. My SMTP
server requires authentication and the following is the code snippet which
I've been using:

MailMessage msg = new MailMessage();
SmtpClient server = new SmtpClient();
System.Net.NetworkCredential credentials = new
System.Net.NetworkCredential(Username, Password);

msg.From = new MailAddress(From, DisplayName);
msg.To.Add(To);
msg.CC.Add(Cc);
msg.Bcc.Add(Bcc);
msg.Subject = Subject;
msg.Body = Body;
msg.IsBodyHtml = true;
server.Host = SMTPServer;
server.UseDefaultCredentials = false;
server.Credentials = credentials;
server.Send(msg);

I get an exception which says

"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".

I have tried increasing the timeout and that too didn't help. I am using VS
2005 Beta 2 on a W2K3 Server Standard Edition.

Any inputs will be much appreciated. Thanks.
 
Seems to be plain "Connection failed" message... Have you tried verify the
connection by typing "telnet <smtp server> 25"?
 
Back
Top