[Solved] C# cancel an email sending using smtpClient [closed]


Quite bluntly, this has XY problem written all over it.

Once you call Send, there is no mechanism to cancel the message – the class doesn’t raise any events before it sends the email or anything, it just sends it. Just make sure you’re actually ready to send the message before you send it.

The actual use case for this is quite small anyway; suppose, just for argument, that the Send operation takes 2 seconds (and it could easily take a lot less); what are the odds that someone will change their mind (or even be able to act quickly enough to stop it from going out) in those 2 seconds?

You’d be better off building the email message completely and then sending it (rather than calling Send, canceling, finishing building it, and then sending it again).

TL;DR You can’t, shouldn’t, and don’t need to cancel the Send operation – just don’t start it until you know you’re ready.

solved C# cancel an email sending using smtpClient [closed]