Unable to send mail using System.Net.Mail

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

Lau Lei Cheong

Seems to be plain "Connection failed" message... Have you tried verify the
connection by typing "telnet <smtp server> 25"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top