开发者

Send email asynchronously from an WCF 4 REST service

开发者 https://www.devze.com 2023-03-10 18:49 出处:网络
I have a WCF 4 REST service which does some processing and then returns back immediately. Now there is a need to send an email asynchronously every time this service is called. Is there some开发者_运维

I have a WCF 4 REST service which does some processing and then returns back immediately. Now there is a need to send an email asynchronously every time this service is called. Is there some开发者_运维百科 way I can achieve this without needing to queue the email in a DB and then use a Windows service to send out the email?


I never used it, but SmtpClient.SendAsync seems to be the right tool for the job.

From MSDN, emphasis mine:

Sends the specified e-mail message to an SMTP server for delivery. This method does not block the calling thread and allows the caller to pass an object to the method that is invoked when the operation completes.

This way your service can return immediately after posting the request to send the email and you can even register a callback to know when the send email operation completes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号