簡體   English   中英

使用C#異步在Azure上通過SendGrid發送電子郵件,等待

[英]Sending emails with SendGrid on Azure using C# async, await

我正在按照本教程使用SendGrid從我的Azure Web角色發送電子郵件。

這是教程中的相關部分:

// Create credentials, specifying your user name and password.
var credentials = new NetworkCredential("username", "password");

// Create an REST transport for sending email.
var transportREST = REST.GetInstance(credentials);

// Send the email.
transportREST.Deliver(myMessage);

在我看來, transportREST.Deliver函數是同步的。 因為它正在執行IO,所以我更喜歡使用新的.NET 4.5 異步,而是使用await (我所有其他代碼都是完全異步的)。 這可能嗎? 是否有用於SendGrid的異步API或某種方式包裝現有調用?

當前,SendGrid C#庫沒有異步方法,因為我們想保持與.NET 4.0的兼容性。

您可以輕松地自己進行此更改。 實際上, 是我決定堅持使用.NET 4.0之后,后來又撤消的一次提交

更新:從2013年10月24日和sendgrid-csharp 1.2.1開始,有可用的DeliverAsync方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM