Last post Sep 28, 2007 05:53 PM by gclapp
Dec 08, 2006 03:54 PM|Eddyaspnet|LINK
I posted the following question under "security- membership controls" but did not receive a reply. Perhaps I should post it here under localization and will get the right people to read and hopefully have the answer (Moderator, if I am not allowed to post
the same posting twice, please forgive me and simply delete this. Thanks)
I use the <%Password%> and <%Username%> to insert the password and username to a html to create my own email. However, my problem is the password and usename can only be read properly using unicode encoding. Instead, I like them to be displayed properly
when the GB2312 encoding is used (since most of my site's users uses mail clients that are set with GB2312 and will always read emails using the GB2321 encoding.
Some web based email clients will not even allow the user to switch to the unicode encoding.)
I have tried everything I can think of to make it work- saving the file in GB2312 encoding, use GB2312 meta tags, use the "<%@ Page RequestEncoding="gb2312" ResponseEncoding="gb2312" %>", etc. Nothing works. Can someone help? Thanks
Dec 09, 2006 05:39 PM|Dejan Vesic|LINK
static byte ConvertUTF82OtherEncoding(string utf8String, string codePageForTargetEncoding)
byte utf8AsBytes = Encoding.UTF8.GetBytes(utf8String);
return Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding( codePageForTargetEncoding), utf8AsBytes);
Dec 10, 2006 11:42 PM|Eddyaspnet|LINK
Thanks for your help and as soon as I found some time, I will try out your solution. However, off the top of my head, I think I will encounter this problem with your solution...
Even if the text is in gb2312, by the time the email gets to the user, it becomes gibberish. The reason I know is because I tried sending gb2312 encoded text, it is gibberish by the time asp.net converts it to an email and send it to the user. So by converting
the username and password first to gb2312, it will simply repeat the above scenerio. ASP.net is doing something behind the scenes that is causing this problem.
But in any case, I appreciate your suggestion and as soon as I find some time, I will still give it a try- again thank you.
Dec 11, 2006 03:13 AM|Dejan Vesic|LINK
Ok, I am sorry if I am asking obvious, but did you try something like:
// send the mail
MailMessage msg = new MailMessage();
msg.IsBodyHtml = false;
msg.BodyEncoding = Encoding.GetEncoding("gb2312");
msg.SubjectEncoding = Encoding.GetEncoding("gb2312");
msg.From = new MailAddress(txtEmail.Text, txtName.Text);
msg.Body = txtMessage.Text;
No conversion at all - just compose message, specify encoding and send - what are results?
Dec 11, 2006 11:14 AM|Eddyaspnet|LINK
Thank you for your suggestion. What you posted makes perfect sense to try... but sorry... I should have stated in the original post that I am looking for a solution specifically for "Visual Web Developer 2005 Express Edition".
I use their PasswordRecovery control...
<asp:PasswordRecovery ID="PasswordRecovery1" runat="server">
<MailDefinition BodyFileName="~/EmailBody_gb2312.txt" Priority="High" Subject="This is your password">
Do you know if it is at all possible to include Encoding.GetEncoding("gb2312") somehow into this. If yes, how?
If it is not possible, I just may have to completed drop this passwordrecovery control and write the entire code (as you have provided above) for this password recovery page myself Thank you.
Dec 11, 2006 11:33 AM|Dejan Vesic|LINK
Of course, try something like that:
- add additional attribute to to PasswordRecovery:
- than do little programming:
void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
e.Message.IsBodyHtml = false;
e.Message.BodyEncoding = Encoding.GetEncoding("gb2312");
Dec 11, 2006 01:55 PM|Eddyaspnet|LINK
Thanks for leading me in the right direction. Add attributes? hmm...I hate programming but I guess if I must... I must.
When I come up wiht the exact code that works, I will come back and post it (hope it will help others.)
Again, thank you so much.
(This .net and visual web studio thing really isn't a "one stop shopping" like I hope it will... but atleast microsoft is smart enough to create a forum like this to help out.) [:P]
Dec 11, 2006 02:00 PM|Dejan Vesic|LINK
But, again, your request is rather unorthodox [:)]
Sep 28, 2007 05:53 PM|gclapp|LINK
The solution turned out to be rather simple and not so obvious.
When you save the e-mail template file, make sure you save the file with UTF8 encoding (or other encoding). In Visual Studio, File->Advanced Save Options... and select the desired encoding. Then, there is no need to set the encoding programatically as
the input file will be correct.
Once I changed the template file encoding and saved it (yes, don't forget to save it-- doh!), the e-mails came through correctly encoded and all characters displayed correctly.
UICulture Language Control Controls ASPNET
Visual Studio 2005
Kanji Email Subject encoding