Reputation: 2042
I have MVCMailer installed at my app. But When i sent the mail with russian charset body i get something like this:
Ïðèâåòñòâóåì Âàñ íà ñàéòå
Good looking, isnt it? :)
For detailed info, can show IUserMailer.cs:
namespace photostorage.Mailers
{
public interface IUserMailer
{
MailMessage Welcome(string userMail, string login, string password);
MailMessage PasswordReset();
}
}
And UserMailer.cs:
public virtual MailMessage Welcome(string userMail, string login, string password)
{
var mailMessage = new MailMessage{Subject = "Добро пожаловать на FotoStorage.org"};
mailMessage.To.Add(userMail);
ViewBag.login = login;
ViewBag.password = password;
PopulateBody(mailMessage, viewName: "Welcome");
return mailMessage;
}
_Layout.cshtml:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
@RenderBody()
</body>
</html>
And Welcome.cshtml
<div>
<div><h1>Приветствуем Вас на сайте ......</h1></div>
<div>
<p>
Ваш логин: @ViewBag.login
Ваш пароль: @ViewBag.password
</p>
<p>
Постоянная ссылка на Ваши фото - .......
</p>
</div>
</div>
Thanks a lot! :)
Upvotes: 0
Views: 979
Reputation: 4538
Make sure also your .cs file (source code) where you set subject is saved in UTF8.
Upvotes: -1
Reputation: 61
First add the following:
x.BodyEncoding = Encoding.UTF8;
x.SubjectEncoding = Encoding.UTF8;
Then add the following override to the class derived from MailerBase:
public override AlternateView PopulateHtmlPart(MailMessage mailMessage, string viewName, string masterName, Dictionary<string, string> linkedResources)
{
var htmlPart = base.PopulateHtmlPart(mailMessage, viewName, masterName, linkedResources);
htmlPart.ContentType.CharSet = mailMessage.BodyEncoding.HeaderName;
return htmlPart;
}
Voila...
Upvotes: 6
Reputation: 887453
Make sure that your template is saved as UTF8 (which should be the default for new files).
Upvotes: 2
Reputation: 887453
Set MailMessage.BodyEncoding = Encoding.UTF8
.
You may also need to set SubjectEncoding
.
Upvotes: 4