Click to See Complete Forum and Search --> : Sending mail through port 465 or 587


Auriion
March 12th, 2009, 03:28 PM
Here's the code I'm working with:
--
String from = "sender";
String to = "recipient";
String smtp = "smtp.xxx.com";
String userName = "xxx@xxx.com";
String password = "xxxx";
String subject = "This is a test subject";
String bodyText = "This is a test email";

MailMessage message = new MailMessage(from, to, subject, bodyText);
//Sets the host and port in the arguments respectively
SmtpClient emailClient = new SmtpClient(smtp, 587);
NetworkCredential SMTPUserInfo = new NetworkCredential(userName, password);

emailClient.UseDefaultCredentials = false;
emailClient.Credentials = SMTPUserInfo;
emailClient.EnableSsl = true;
emailClient.Send(message);
--

I've tried a great number of different combinations of configurations and nothing has worked. I even checked to make sure none of my ports were being blocked by possible firewalls.

The only time the email works is when I use port 25, however my smtp host states that I can also use port 587 for sure.

Is there something I am missing?

I've also tried using gmail as an smtp server with no luck. If someone could post the code they used to successfully deliver email through smtp.gmail.com (without username and password of course) that would be very helpful.

Thanks for the feedback ahead of time.

Auriion
March 12th, 2009, 03:48 PM
Whoops! I forgot to let you know my specs.

I'm using .Net 2.0 in visual web developer express 2008

Auriion
March 12th, 2009, 06:58 PM
I've figured out the issue.

It turns out the ports were being blocked by a firewall on the gateway of our network which is controlled by our ISP.
I had to call up our ISP and have them unblock them and now it sends emails like a charm.

... now if only I could keep them from going to the spam folder ...

Hope this is helpful to someone!