Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending plain text e-mails using SendGrid

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?

like image 821
Paul Michaels Avatar asked Feb 22 '18 17:02

Paul Michaels


People also ask

Can we send SMS using SendGrid?

Using SMS and Email Together Regardless of who you're trying to contact or where they are, you can now complete the customer engagement package with another robust API: SMS.

How do I send an email to plain text?

To send an email in plain text in Gmail, compose a message as you normally would. At the bottom of the compose window, click the three-dot menu and then click Plain text mode. This setting acts as a toggle. To de-activate plain-text mode, re-select the menu option.

Should I send emails as plain text or HTML?

While HTML email still has issues, most notably with compatibility, it still wins in the end. Plain text emails are often reliable in terms of email deliverability. Still, when it comes to overall user experience, visual display, and brand consistency, HTML wins out, hands down.


1 Answers

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.

like image 115
Lennart Stoop Avatar answered Sep 28 '22 14:09

Lennart Stoop