Not sure why this is happening. Every where I\'ve search tells me that i\'m doing this right. But every time I try and send the mail, it times out on the smtpserver.Se
As @kostyan said, the right port is 587, but to authenticate you need to allow access from less secure apps in your gmail account. Try it here
It worked for me, hope it helps..
Are you sure about the port, in my code I have it as 587, otherwise looks similar and it works.
This thread helped me. I'm not sure why this code worked and mine wasn't.
Sending email in .NET through Gmail
using System.Net;
using System.Net.Mail;
var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@example.com", "To Name");
const string fromPassword = "fromPassword";
const string subject = "Subject";
const string body = "Body";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
I have found that when I tried to spoof the sender address using google smtp (for instance, using FromAddress as something other than the name of my gmail account) I was getting either authentication error messages or simply timing out.