andrewdavey / postal

Email sending for asp.net mvc using the view engine system to render emails.
http://aboutcode.net/postal
MIT License
536 stars 169 forks source link

Subject encoding #183

Closed dlidstrom closed 2 years ago

dlidstrom commented 2 years ago

I'm sending mails with non-english characters in the subject, and they end up being encoded as html:

test åäö ÅÄÖ

This is how the subject ends up looking.

My template looks like this:

@model Snittlistan.Web.Models.SendEmail
To: @Model.To
From: @Model.From
@if (string.IsNullOrEmpty(Model.ReplyTo) == false)
{
    @:Reply-To: @Model.ReplyTo
}
Bcc: @Model.Bcc
Subject: @Model.Subject
Content-Type: text/html; charset=utf-8

<html>
<head>
</head>
<body>
    @Model.Content
</body>
</html>

Any idea on how to fix this? Should I specify the encoding in the subject?

dlidstrom commented 2 years ago

Best way to solve a problem yourself is to first file an issue. This seems to work:

Subject: @(string.Format("=?utf-8?B?{0}?=", Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Model.Subject))))