0
我已经升级到SendGrid API v3,用于我的ASP.Net项目,并发现旧的代码在IIdentityMessageService.SendAsync函数中发送电子邮件的问题。SendGrid API v3 post breaks示例
我的代码如下:
Public Class EmailService
Implements IIdentityMessageService
Public Function SendAsync(message As IdentityMessage) As Task Implements IIdentityMessageService.SendAsync
Dim sg = New SendGridAPIClient(ConfigurationManager.AppSettings("SendGridApiKey"))
Dim from = New Email("[email protected]", "InvestorsEdge")
Dim [to] = New Email(message.Destination)
Dim Content = New Content("text/html", message.Body)
Dim Mail = New Mail(from, message.Subject, [to], Content)
Dim response = sg.client.mail.send.post(requestBody:=Mail.Get()).GetAwaiter().GetResult()
If Not response.StatusCode = Net.HttpStatusCode.Accepted Then
AtlasDb.Log.ErrorFormat("EmailService.SendAsync", "Abnormal response code ({0}", response.StatusCode)
End If
Return Task.FromResult(response.StatusCode)
End Function
End Class
这段代码在API第2工作正常,但访问响应对象时,我现在得到一个System.MissingMemberException。
在新的例子中,这个帖子正在等待,但是我可以将SendAsync签名更改为Async,因为它不是我的代码。 。