Tutorial :Unable to send mail asynchronously



Question:

I'm using a separate class and unique method for sending mail.All my web pages, will call the method to send the mail. But, I'm using Client.SendAsync() to send the mail. The following error occurs while sending the mail asynchronously.

"Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event"

I set Async=true in @page directive, but, as I'm using separate class, so no use of it. Is there any other way to overcome this problem?


Solution:1

This article may be of some help to you:

Fire and Forget Email, Webservices and More in ASP.NET


Solution:2

Seems you just need to start your async task before PreRenderComplete event; do you mind to post some relevant ASP.NET code?

Also, read this: Running an asynchronous operation triggered by an ASP.NET web page request


Solution:3

Setting Async to true is OK if that separated class is declared, instantiated and within the context of the page request.

However you probably need to handle SendCompleted event.

See the sample codes in this MSDN Reference.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »