I'm trying to send emails that contains special characters like á, é, ó, í, ú, etc. My code looks like this:
try
{
Mail message = Mail.GetInstance();
foreach (Users u in users)
{
message.AddBcc(u.Email);
}
message.From = new MailAddress(Microsoft.WindowsAzure.CloudConfigurationManager
.GetSetting("emailFrom"), Microsoft.WindowsAzure.CloudConfigurationManager
.GetSetting("emailFromName"));
message.Subject = Microsoft.WindowsAzure.CloudConfigurationManager
.GetSetting("emailSubject");
message.Html = "<meta charset=\"UTF-8\"/>" +
Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("emailText1") +
" " + address+ ".<br/>" +
Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("emailText2");
var transport = SMTP.GetInstance(new NetworkCredential(
Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("emailLogin"),
Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("emailPass")));
transport.Deliver(message);
isEmailSent = true;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message + " \n " + ex.InnerException + " \n " + ex.StackTrace);
isEmailSent = false;
}
I tried to specify the charset in the Html I'm sending but it doesn't work, instead of sending this San Jerónimo Amanal, this is what is being sent San Jerónimo Amanal.
How can I send it in the correct encoding? Any help will be appreciated.
EDIT
I tried this two approches:
message.Html = "<meta charset=\"UTF-8\"/>" +
Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("emailText1") +
" " + address+ ".<br/>" +
Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("emailText2");
And this:
message.Html = Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting
("emailText1") + " " + address+ ".<br/>" +
Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("emailText2");
But the email is still being sent with the wrong encoding.
EDIT 2
I tried the answer on this question Converting Unicode strings to escaped ascii string, more especifically, I tried the method EncodeNonAsciiCharacters but I got this in the email San Jer\u00c3\u00b3nimo Amanal. Did I take the wrong approach in this one?