smsohan / MvcMailer

A Mailer for ASP.Net MVC that forms the Email Body using MVC Views (Razor etc.) following Ruby on Rails ActionMailer style
MIT License
582 stars 178 forks source link

Encoding of UTF-8 content #11

Closed jstclair closed 13 years ago

jstclair commented 13 years ago

I'm running into an encoding issue - Utf-8 text is the mail message is improperly encoded. So far, I've done the following:

But the only way to get the text to render correctly in the mail message is if I use:

@Html.Raw(ViewBag.MyUtf8Property)

rather than:

@ViewBag.MyUtf8Property

This seems counter-intuitive to me, but I'm still in need of at least one more coffee today. Any ideas?

smsohan commented 13 years ago

MvcMailer doesn't change any encoding in itself. However the .net framework does. So, whatever encoding related hacks you use when sending mail via System.Net.Mail applies to MvcMailer too. And whatever helper you use in your MVC views should be used to create mailer views too.


Sent from my iPhone

On 2011-04-18, at 8:40 AM, jstclair reply@reply.github.com wrote:

I'm running into an encoding issue - Utf-8 text is the mail message is improperly encoded. So far, I've done the following:

  • Saved the mailer's View.text.cshtml as utf-8 (initial version was ANSI)
  • configured the MailMessage (in the MailerBase-derived class) with BodyEncoding and SubjectEncoding both set to Encoding.UTF8
  • pass some utf-8 text via the ViewBag

But the only way to get the text to render correctly in the mail message is if I use:

@Html.Raw(ViewBag.MyUtf8Property)

rather than:

@ViewBag.MyUtf8Property

This seems counter-intuitive to me, but I'm still in need of at least one more coffee today. Any ideas?

Reply to this email directly or view it on GitHub: https://github.com/smsohan/MvcMailer/issues/11