![](/img/trans.png)
[英]my Internet email client (such as Hotmail) doesn't receive SMTP sent from my new Azure Windows 2012 server VM Visual Basic 2010 app
[英]SendGrid doesn't send email from Azure Windows 2012 VM
我设置了SendGrid帐户并获得了密钥和密码。 我的VisualBasic 2015控制台应用程序运行DeliverAsync时没有错误,但是电子邮件没有到达Internet收件人(我的Hotmail帐户)。 另外,task.wait()会引发异常“错误的用户名/密码”,该异常会在末尾发布
Azure上的Wireshark没有显示SMTP,但我不知道SendGrid是否使用SMTP。
这是应用程序:
' Create the email object first, then add the properties.
Dim myMessage As SendGridMessage
myMessage = New SendGridMessage()
' Add the message properties.
myMessage.From = New MailAddress("<my email addr>")
' Add multiple addresses to the To field.
myMessage.AddTo("<destination email addr 1>")
myMessage.AddTo("<destination email addr 2>")
myMessage.AddTo("<destination email addr 3>")
myMessage.Subject = "Testing the SendGrid Library 2"
'Add the HTML and Text bodies
myMessage.Html = "<p>Hello World!</p>"
myMessage.Text = "Hello World plain text!"
Dim credentials As NetworkCredential
credentials = New NetworkCredential("apikey", "<my api pw>")
transportWeb = New Web(credentials)
Dim task = transportWeb.DeliverAsync(myMessage)
Try
task.wait()
Catch ex As AggregateException
Stop '<<<<<<<<< I GET: "Bad username / password"
Catch
End Try
例外情况:“用户名/密码错误”
DeliverAsync返回Task ,因此您需要等待任务。
Await transportWeb.DeliverAsync(myMessage)
当然,要使用await
关键字,您的方法需要标记为async
。 如果您不想这样做,则可以手动等待任务。
Dim task = transportWeb.DeliverAsync(myMessage)
task.Wait()
您应该熟悉基于任务的异步模式(TAP) 。 通常,当函数名称以-Async
结尾时,它将使用TAP。
我通过创建新的VB网络应用程序而不是win应用程序来使其工作。 VB>创建新项目> Web应用程序> MVC,然后进行props>引用> NU。Mgr>搜索SendGrid> Install,就是这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.