I'm attempting to send mail through gmail using the below code, but I keep getting an errors stating "Unable to connect to the remote host". I've double-checked my config and everything looks fine to me. Anyone see something I'm missing?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("mymail@gmail.com", "mypass");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
MailMessage mail = new MailMessage();
mail.From = new MailAddress("mymail@gmail.com");
mail.To.Add("tomail@tomail.org");
mail.Subject = "subject thing";
mail.Body = "dubbly doo";
try
{
client.Send(mail);
}
catch(SmtpException e)
{
Console.Write(e.InnerException.Message);
Console.ReadLine();
}
}
}
}