【问题标题】:Azure SendGrid doesn't send any email and raises no errorAzure SendGrid 不发送任何电子邮件并且不引发错误
【发布时间】:2016-10-12 01:13:53
【问题描述】:

我一个小时前刚刚创建了我的 SendGrid 帐户。然后,我使用 Microsoft 的示例代码在我的 PC 上创建了一个 C# Console 应用程序。它运行良好,没有任何错误消息,但没有发送电子邮件,也没有在系统中留下任何痕迹。我该怎么办?

using System;
using System.Net;
using System.Net.Mail;
using SendGrid;
using System.Collections;
using System.Collections.Generic;


namespace SendGridTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var myMessage = new SendGridMessage();
            myMessage.From = new MailAddress("noreply@teacherspet.net.au");

            List<String> recipients = new List<String>
            {
                @"my1@gmail.com",
                @"my2@gmail.com",
                @"my3@gmail.com"
            };

            myMessage.AddTo(recipients);
            myMessage.Subject = "Testing the SendGrid Library";
            myMessage.Html = "<p>Hello World!</p>";


            var credentials = new NetworkCredential("azure_6e0d0...@azure.com", "mypassword");
            var transportWeb = new Web(credentials);
            transportWeb.DeliverAsync(myMessage);
        }
    }
}

【问题讨论】:

  • 您正在调用没有await 的异步方法。试试transportWeb.DeliverAsync(myMessage).GetAwaiter().GetResult();
  • 非常感谢布伦丹!在我按照您的建议进行操作之后。

标签: email azure sendgrid


【解决方案1】:

正如 Brendan Green 建议的那样,一旦将最后一行更改为

transportWeb.DeliverAsync(myMessage).Wait(); 

成功了。谢谢布伦丹!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-02
    相关资源
    最近更新 更多