I want to send user a localized email, but it seems the text retrieved from resource file are based on my culture.
SmtpClient client = new SmtpClient();
client.Host = "xxx.xxx.xxx";
client.Credentials = new NetworkCredential("name", "password");
MailMessage mm = new MailMessage();
mm.Sender = new MailAddress("xxx@xxx.com");
mm.From = new MailAddress("xxx@xxx.com");
mm.To.Add(new MailAddress(email));
mm.Subject = Localization.EmailUserActiveTitle;
mm.Body = "<div><h3>" + Localization.EmailUserActiveBodyPart1 + "</h3></div></br>" +
"<div>" + Localization.EmailUserActiveBodyPart2 + "</div>" +
"<div><b>" + content + "</b></div></br>" +
"<div>" + Localization.EmailUserActiveBodyPart3 + "</div>" +
"<div>" + Localization.EmailUserActiveBodyPart4 + "</div>";
mm.IsBodyHtml = true;
mm.Priority = MailPriority.Normal;
client.Send(mm);
But when i retrieve Localization.EmailUserActiveBodyPart1 it is localized base on my current culture.
how can i retrieve specified culture resource file?
The ResourceManager uses the Thread.CurrentThread.CurrentUICulture property to determine which localized language version of a resource to load.
So if you want to force localization to a specific language (e.g. the language preference associated with the user you are sending email to), then just do this before your code:
And clean up* just after your code:
*Obviously this is not a reliable clean-up. A
finallyblock or wrapping this language-switching functionality in anIDisposableand using ausingblock would prevent your code running in a random language in case of a failure, but that’s outside the point.