views:

170

answers:

3

I am trying to send an smtp email through gmail's smtp server using the code below:

MailMessage message = new MailMessage("[email protected]", "[email protected]", "Testing SMTP", "Test, yo");
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Host = "smtp.gmail.com";
client.Port = 587;
client.Credentials = new NetworkCredential("[email protected]", "myPassword");
client.Send(message);

Using the same code my friend successfully sent me an email from another network, but .NET throws the error "No connection could be made because the target machine actively refused it 74.125.91.109:587". This has to be a network issue right?

My network admin claims there are no blocked outbound ports and my firewall is entirely off, what else could be causing this? I have tried Purdue's smtp server as well (smtp.purdue.edu), and it fails with the same message.

+2  A: 

Turn off any antivirus program.

Regarding the test to Purdue, are you sure that they use port 587?

ho1
Good point. My McAfee virus scanner was blocking outbound mail ports to prevent viruses from sending out spam from my computer.
JasCav
Turning off McAfee did it. I can't believe that was the issue this whole time. Thanks a million guys!
caltrop
A: 

You should use port 465 for SSL according to this

Lee
A: 

Change the port to 465. It worked for me.

Liza V.