Alex
Alex

Reputation: 36161

Sending mail with C#

I set up my hMailServer on my windows 2008 machine, and I'm trying to send emails.

When I do it with C#

MailMessage message = new MailMessage();
message.From = new MailAddress(from, "John");
message.To.Add(new MailAddress(to));
message.Subject = subject;
message.Body = body;
SmtpClient client = new SmtpClient("mail.example.com");
client.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
client.Send(message);

But when I try to send emails with a windows live email client, it gives me an error

The connection to the server has failed

All the settings are exactly the same. I tried several email clients, but it doesn't work. It never happened to me before. I just moved from one machine to another, and got this problem.

I can receive mail in the client though...

Upvotes: 3

Views: 1321

Answers (1)

Brian R. Bondy
Brian R. Bondy

Reputation: 347556

Try to telnet to port 25, can it connect?

Open up command prompt:

telnet mail.example.com 25

If it cannot connect (which is what I expect) then you have a problem that is not code related but firewall related. (Or perhaps you're trying to connect to the wrong port if they're running SMTP on a non standard port)

Upvotes: 3

Related Questions