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?
Contentsproperty of theSendGridMessage, right before you send? My guess is that it contains HTML, and you simply need to remove that entry from the list. Just a guess, based on the source code. I've not used SendGrid myself. - masonview sourceof the message? - astaykovmsg.AddContent(MimeType.Text, "hello");(obviously without setting thePlainTextContentwhen constructing the object) - Lennart Stoop