使用SendGrid发送电子邮件不适用于css样式

时间:2017-03-30 12:36:26

标签: c# sendgrid sendgrid-templates

我有一个简单的HTML代码,可以使用C#API Sendgrid和模板发送到某个电子邮件: enter image description here

当我试图看到它的预览看起来像我预期的那样: enter image description here

但是当电子邮件发送时,它并没有识别出"样式"或任何CSS代码..

enter image description here

这是我的代码:

static async Task Execute()
    {
        var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        var client = new SendGridClient(apiKey);
        var msg = new SendGridMessage();
        msg.SetFrom(new EmailAddress("test@example.com", "Example User"));
        msg.SetSubject("I'm replacing the subject tag");
        msg.AddTo(new EmailAddress("myEmail", "Nathiel"));
        //msg.AddContent(MimeType.Text, "I'm replacing the <strong>body tag</strong>");
        msg.SetTemplateId("MyTemplateId");
        msg.AddSubstitution("-cepFrom-", "54315-310");
        var response = await client.SendEmailAsync(msg);
        Console.WriteLine(response.StatusCode);
        Console.WriteLine(response.Headers.ToString());
        Console.WriteLine("\n\nPress any key to exit.");
        Console.ReadLine();
    }

我不知道出了什么问题!

1 个答案:

答案 0 :(得分:1)

由于样式是客户端关注的问题,因此在电子邮件中呈现CSS的方式有很多种。一般来说,大多数事情都被困在过去。使用HTML 4并仅支持基本的CSS属性是最好的方法,以确保您的电子邮件在许多不同的客户端中正确呈现。

这里的主要问题是你需要内嵌CSS样式而不是将它们放在头部。这是一个很好的入门指南:https://litmus.com/blog/a-guide-to-css-inlining-in-email

相关问题