【问题标题】:SendGrid V3 api with C#. email not sending带有 C# 的 SendGrid V3 api。电子邮件不发送
【发布时间】:2023-03-15 05:13:01
【问题描述】:

这段代码有问题吗?我已经将我的电子邮件放入我的代码中,但我没有收到任何电子邮件。 我有一个提示,它不起作用,因为我使用的是 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);

        }

【问题讨论】:

  • 您从 sendgrid 得到什么响应?如果您认为 API 密钥是问题,那么您应该联系 sendgrid 支持。
  • 什么反应?当我尝试运行该功能时,我只是将代码放入我的网络服务中,没有错误。但我没有收到任何电子邮件
  • 什么反应?当我尝试运行该功能时,我只是将代码放入我的网络服务中,没有错误。但我没有收到任何电子邮件
  • var response = await client.SendEmailAsync(msg); 这个回复。您是否调试了代码并检查了 response 变量中的值?
  • 返回值为“WaitingForActivation”

标签: c# sendgrid-api-v3


【解决方案1】:

代码运行良好。问题是我使用的是 API 密钥 ID,而不是 sendgrid 生成的 API 密钥。

Please refer to this thread for more info

【讨论】:

    猜你喜欢
    • 2023-04-10
    • 1970-01-01
    • 2016-11-30
    • 2018-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多