Reputation:
I have a simple HTML code to send to a certain e-mail using C# API Sendgrid and Templates :
And when I try to see the preview of it looks as I expected :
But when the E-mail is delivered it doesn't recognize the "style" or any css code..
This is My Code :
static async Task Execute()
{
var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
var client = new SendGridClient(apiKey);
var msg = new SendGridMessage();
msg.SetFrom(new EmailAddress("[email protected]", "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();
}
I don't know what's wrong!
Upvotes: 4
Views: 9331
Reputation: 9854
Because styles are a client-side concern, there is a wide variety of ways to render CSS in emails. In general, most things are stuck in the past. Using HTML 4 and supporting only basic CSS properties is the best way to go in order to ensure your emails render properly in many different clients.
The main problem here is that you need to inline your CSS styles rather than place them in the head. Here is a good guide to get started: https://litmus.com/blog/a-guide-to-css-inlining-in-email
Upvotes: 2