What I have done so far with no results:
Code (Fails on the connect method):
public async Task<SmtpClient> GetSmtpClient()
{
SmtpClient client = new();
try
{
await client.ConnectAsync(smtpAddress, port, MailKit.Security.SecureSocketOptions.Auto);
await client.AuthenticateAsync(username, password);
}
catch (Exception)
{
throw;
}
return client;
}
Results in:
Exception: 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.
StackTrace:
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---
At the end:
I really appreciate any clues you can give me. All the best.
This problem turned out to be the mail server blocking the IP of the webapp. It was not clear why this IP was blocked. After they unblocked the Ip the Smtp client connected without issues and all was good again.