Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core - Send email without wait

I have an APS.NET Core 5 Web API:

I have this:

await _mailSender.SendMailAsync(entity.Id);

But, I don't want to wait for the email sender to return Ok for client. I want to continue code execution and send email in background.

How can I do this?

like image 296
Marcelo Antunes Fernandes Avatar asked Feb 17 '26 08:02

Marcelo Antunes Fernandes


1 Answers

I did this using HangFire to queue the email to send.

//send email
BackgroundJob.Enqueue(() => _mailSender.SendMailAsync(entity.Id));
like image 81
Marcelo Antunes Fernandes Avatar answered Feb 18 '26 22:02

Marcelo Antunes Fernandes