MailKit
MailKit copied to clipboard
Catch exception "Invalid domain name"
Recently I found such an error in the logs NewRelic.

The send method is wrapped in a try-catch design. How can I catch exactly the "nvalid domain name" error? Since I want to make a separate processing logic for it.
The address that caused this error looked like this "[email protected]".
try
{
_smtpClient.Send(mail);
}
catch (Exception ex)
{
// TODO: Invalid domain name
}
You might be able to use the SmtpCommandException ErrorCode and/or StatusCode properties to help narrow it down. After that, you'll have to use something like ex.Message.StartsWith ("Transaction failed: Invalid domain name:")