I’m still getting “Failure sending mail.” exception. The inner exception is “Unable to connect to the remote server” and the inner exception of that is “A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond”. I’m pretty sure the cause of this is not the firewall setting. Does anyone know what I can do about it? Thanks.
var mail = new MailMessage("username@gmail.com", "destination@gmail.cz")
{
Subject = "Testing subject",
Body = "Testing body"
};
try
{
var client = new SmtpClient("smtp.google.com", 465)
{
EnableSsl = true,
Credentials = new NetworkCredential("username@gmail.com", "password")
};
client.Send(mail);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Here is the Google settings needed:
Incoming Mail (POP3) Server – requires SSL: pop.gmail.com
Use SSL: Yes
Port: 995
Outgoing Mail (SMTP) Server – requires TLS3 or SSL: smtp.gmail.com
(use authentication)
Use Authentication: Yes
Port for TLS/STARTTLS: 587
Port for SSL: 465
Account Name: your full email address (including @gmail.com or
@your_domain.com)
Email Address: your email address (username@gmail.com or
username@your_domain.com)
Password: your Gmail password