MailKit icon indicating copy to clipboard operation
MailKit copied to clipboard

Catch exception "Invalid domain name"

Open Prazdnik opened this issue 5 years ago • 1 comments

Recently I found such an error in the logs NewRelic. image

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 }

Prazdnik avatar Jun 15 '21 07:06 Prazdnik

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:")

jstedfast avatar Jun 15 '21 14:06 jstedfast