A connection attempt failed because the connected party did not appropriately respond after some time, or an established connection failed because the connected host has failed to respond 142.251.5.109:587
I have tried many solutions (SendGrid, MailTrap, SmtpClient, MailKit...) on google, allowed ports on the firewall, and used different email ids... but I am getting the same error every time. Now I suspect that there might be some issue with my system or my IP which is blocked everywhere for sending email via code. Any Idea? The last code which I used
private async Task SendEmail(IdentityMessage message)
{
try
{
var msg = new MimeKit.MimeMessage();
msg.From.Add(new MimeKit.MailboxAddress("name", "email"));
msg.To.Add(new MimeKit.MailboxAddress("Hello!", message.Destination));//email
msg.Subject = message.Subject;
msg.Body = new MimeKit.TextPart(MimeKit.Text.TextFormat.Html) { Text = message.Body.ToString() };
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.Connect("smtp.gmail.com", 587, false);//also tried different smtp, different ports 25, 465, 2525 and 3rd parameter to True etc
client.Authenticate("email", "password");
client.Send(msg);
client.Disconnect(true);
}
}
catch (Exception ex)
{
throw ex;
}
}