c# - Sendgrid X-SMTP-API 在使用 EnableTemplateEngine 时返回错误

标签 c# asp.net-core sendgrid

我实际上使用的是 ASP .NET Core 1.1。

项目.json:

"dependencies": {
    "SendGrid.NetCore": "1.0.0-rtm-00002",
    "Sendgrid": "8.0.5"
}

用于发送电子邮件的代码:

public Task SendEmailAsync(string email, string subject, string content)
{
    var message = new SendGridMessage();
    message.AddTo(email);
    message.From = new System.Net.Mail.MailAddress("geeks@test.io", "test");
    message.Subject = subject;
    message.EnableTemplateEngine("18d89b42-d094-49fb-86c4-5f5821a2eb67");
    message.Html = "test";
    message.Text = "test";

    var credentials = new System.Net.NetworkCredential(
        _emailSettings.Username,
        _emailSettings.Password
    );

    var transportWeb = new SendGrid.Web(credentials);
    return transportWeb.DeliverAsync(message);
}

当我尝试使用模板 [message.EnableTemplateEngine("18d89b42-d094-49fb-86c4-5f5821a2eb67")] 时,我无法发送电子邮件。但是,任何不使用模板发送的电子邮件都可以按预期工作。

我也试过这个而不是引用 SendGrid SMTP API for Applying Template 的 EnableTemplateEngine :

message.Header.AddFilterSetting("templates", new List<string>() { "template_id" }, "18d89b42-d094-49fb-86c4-5f5821a2eb67");
message.Header.AddFilterSetting("templates", new List<string>() { "enable" }, "1");

我收到此错误:

JSON in x-smtpapi could not be parsed

有什么想法吗?

最佳答案

最后,我没有使用类“SendGridMessage”。

https://github.com/sendgrid/sendgrid-csharp/blob/master/USE_CASES.md

关于c# - Sendgrid X-SMTP-API 在使用 EnableTemplateEngine 时返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41008359/

相关文章:

c# - 将 Lookup<TKey, TElement> 转换为其他数据结构 c#

c# - Visual Studio 2010 的 ReportViewer 组件是否对应于 SQL Server Reporting Services 2008 或 2008 R2?

c# - 如何在 EF Core 中使用 C# 9 记录?

email - SendGrid Link Branding 导致 ssl 问题

php - sendgrid 发送多个收据电子邮件

c# - 无法使用 SendGrid 在 iOS 上打开电子邮件中的通用链接

c# - 在 C# 中创建常量字典

angular - 将自定义 api 端点添加到 ASP :Net Core template

asp.net - GraphQL.NET 如何将枚举添加到 GraphQL 类型

c# - MVC 4 强类型 View 不传递 Controller 模型