Jhayes2118
Jhayes2118

Reputation: 842

How do I send asynchronous emails?

I am trying to send inventory updates to users who have made a request to be emailed when it becomes available. The system is a P2P system. A user will add their inventory and when that happens I want to trigger the email sending.

I want this process to be done without the user having to wait for these emails to be sent. I want this to be fire and forget. The client that adds the inventory needs not know that the emails were sent nor does the page that he is on know that the emails were sent successfully

Everywhere I have seen for a solution to this requires that I set up a web-service to handle this. Is this true? If so, could someone send me in the right direction on where to learn the how to write a web service and it's interface like this.

Upvotes: 0

Views: 225

Answers (3)

Mario
Mario

Reputation: 3445

This isn't exactly an answer to your question but sending an email is a very quick process, even if the SMTP server isn't local. I have done this same thing before without doing an async process and the delay isn't noticable.

Upvotes: 2

CompanyDroneFromSector7G
CompanyDroneFromSector7G

Reputation: 4517

What version of .NET?

Couldn't you just kick-off a process in a new thread that builds and sends an email?

The user wouldn't have to wait then...

Upvotes: 0

Matt
Matt

Reputation: 3680

You could just use a thread to send the email on.

using System.Threading;

Thread t = new Thread(()=>{ 
//put code here that would send your email
 });
t.IsBackground = true;
t.Start(); //this actually will startup the thread and run your code.

Upvotes: 0

Related Questions