I have a simple smtpClient:
var smtp = new SmtpClient { Host = host, ...}; smtp.Send(message);
I may have another host: smtp.gmail.com , smtp.yandex.ru , etc.
When executing smtp.Send(message); I have another exception (it depends on the host) due to the same problem - 2-factor verification is turned off.
For gmail, its System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
For yahoo and yandex its System.Net.Mail.SmtpException depth 0: The operation has timed out. (0x80131500) System.Net.Mail.SmtpException depth 0: The operation has timed out. (0x80131500)
Iām not talking about exceptions from other mail providers now, but how to throw an exception ("you need to enable two-factor verification") only once? Is it possible? Or how to minimize code duplication?
user5515846
source share