Abort sending email

Hi there,

my windows application offers the opportunity to send emails using SMTP_Auth. It works fine.
I was just wondering if there is any possibility to abort the process of sending the email, once "System.Web.Mail.SmtpMail.Send(mail)" is executed.
Imagine you send 20mb (which taked some time) and you want to abort.

How can I do this

Thanks,
Finch82.



Answer this question

Abort sending email

  • Johannes Herbst

    Anybody
  • qUchUnyU

    You can use the Thread.Abort method to abort the execution. Or when you have writen you own send implementation you can read a boolean flag everytime you send a chunk of data to determ if the process is aborted or not.


  • hegde

    You could always launch the Send method on a separate thread and then abort the thread. In fact, for you to even be able to do this, you would have *had* to launch on a different thread.

    While this works, the problem is that you’re not really in control of all of the parts in the process. For example, you can’t abort the request on the mail server. All you can do is stop sending the message. While this might work for your case most of the time, it’s not going to be sufficient in every situation.

    Bruce Johnson [C# MVP]
    http://www.objectsharp.com/blogs/bruce





  • Damien fromOZ

    Hi,

    sending the email runs in another thread and as you said:
    It doesn't stop the request.

    So how can I stop sending the message That's my initial question.

    Thanks,
    Finch82.


  • kobusVB

    Not with the build in class, you can implement the Smtp protocol yourself or look for an existing library that supports this.


  • AlonsoR

    As BJohnson said before,

    aborting the thread will not stop the request on the mail server.
    There must be a way, since every mailclient offers this possibilty.

    Thanks for any help,

    Finch82.


  • Abort sending email