带有C#的SendGrid V3 api。电子邮件不发送

时间:2017-10-09 03:30:01

标签: c# sendgrid-api-v3

这段代码有问题吗?我已将电子邮件放入我的代码中,但我没有收到任何电子邮件。 我有一个提示,它无法正常工作,因为我使用API​​密钥ID而不是API密钥,因为我只看到我的API密钥,因为它只显示一次。如果是这个代码不起作用的原因。有没有办法再次查看您的API密钥?

   public string SendEmailMain()
        {
            SendEmail().Wait();

        }
 static async Task SendEmail()
        {
            common com = new common();
            var apiKey = com.sendGridAPI;
            var client = new SendGridClient(apiKey);
            var from = new EmailAddress("testmail@gmail.com", "test user");
            var subject = "Sending with SendGrid is Fun";
            var to = new EmailAddress("testemai@gmail.com", "teset user");
            var plainTextContent = "and easy to do anywhere, even with C#";
            var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";

            var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
            var response = await client.SendEmailAsync(msg);

        }

1 个答案:

答案 0 :(得分:0)

代码工作得很好。问题是我正在使用API​​密钥ID,而不是由sendgrid生成的API密钥。

Please refer to this thread for more info

相关问题