Reputation: 16695
I'm trying to send a plain text e-mail from a C# function; however, the resulting mail comes through with HTML tags. I've reduced this down to the following console app:
static async Task Main(string[] args)
{
SendGridMessage msg = new SendGridMessage()
{
From = new SendGrid.Helpers.Mail.EmailAddress("[email protected]"),
Subject = "test",
PlainTextContent = "Hello"
};
msg.AddTo(new SendGrid.Helpers.Mail.EmailAddress("[email protected]", "test recipient"));
SendGridClient client = new SendGridClient("mykey");
Response response = await client.SendEmailAsync(msg);
Console.WriteLine(response.StatusCode);
Console.ReadLine();
}
It sends the e-mail fine, but doing a view source on the e-mail shows it to be HTML formatted:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<p>Hello</p>
<img src="https:// ... />
</body></html>
I've tried various combinations, including setting the HtmlContent to plain text (which results in a very different e-mail, but still not plain text), and a syntax such as:
var emailContent = new Content
{
Type = "text/plain",
Value = emailMessage
};
message.Content.Add(emailContent);
I know that there is no intermediary reformatting the message, as I can send a plain text e-mail to myself from outlook.
I'm using SendGrid 9.9.0, but I've tried 9.8.0 in case it's something that has recently changed.
Am I missing something here, or am I expecting SendGrid to be able to do something that it isn't capable of?
Upvotes: 7
Views: 10412
Reputation: 1689
Taken from the SendGrid online docs:
First, login to your SendGrid account, click on “Settings”, then “Mail Settings”, and drop down the Plain Content setting, and then place a check mark in the Don’t Convert Plaintext to HTML option. Be sure to save this setting.
The standard seems to be that e-mails are sent with both HTML and plain text, so a version of plain text is automatically converted to HTML as well.
Upvotes: 9