K
Kevin B Ebert
For the life of me, I can't figure this out. I'm trying to send out
an email written in Korean using SMTP. When I send the message to an
Outlook client, everything works like a champ. But, when I send the
email to a web client, all the characters get screwed up and the email
is not legible. I figured the
System.Web.Mail.MailMessage.BodyEncoding property would control the
encoding of the characters, but, it doesn't seem to help. I've
included some code below:
System.Web.Mail.MailMessage message = new
System.Web.Mail.MailMessage();
// As far as I understand, Code Page 949 is for Korean Characters.
// I've also tried System.Text.Encoding.UTF8 to no avail.
message.BodyEncoding = System.Text.Encoding.GetEncoding(949);
message.BodyFormat = System.Web.Mail.MailFormat.Html;
// The body of the message is pulled from our SQL database.
// When comes in, the Korean characters look fine.
message.Body = "This is where my korean character formatted email will
go.";
message.Cc = "(e-mail address removed)";
message.From = "(e-mail address removed)";
message.Subject = "Subject line";
message.To = "(e-mail address removed)";
I can tell you, I've configured my browser to allow for Korean
characters. So, I don't suspect it is a browser problem. And, to add
complexity, when I compose my email message in Outlook and send it to
my web mail, the message is fine, it works like a champ. So,
therefore, I'm assuming I just don't understand something about
encoding strings. I also tried taking my string and converting to
UTF8 formatted string hoping that would help. I changed the code
above to the following:
System.Web.Mail.MailMessage message = new
System.Web.Mail.MailMessage();
// Need to convert the body string to UTF8
// The body of the message is pulled from our SQL database.
// When comes in, the Korean characters look fine.
string unicodeString = "This is where my korean character formatted
email will go.";
// Create two different encodings.
System.Text.Encoding utf8 = System.Text.Encoding.UTF8
System.Text.Encoding unicode = System.Text.Encoding.Unicode;
// Convert the string into a byte[].
byte[] unicodeBytes = unicode.GetBytes(unicodeString);
// Perform the conversion from one encoding to the other.
byte[] utf8Bytes = System.Text.Encoding.Convert(unicode, utf8,
unicodeBytes);
// Convert the new byte[] into a char[] and then into a string.
// This is a slightly different approach to converting to illustrate
// the use of GetCharCount/GetChars.
char[] utf8Chars = new char[utf8.GetCharCount(utf8Bytes, 0,
utf8Bytes.Length)];
utf8.GetChars(utf8Bytes, 0, utf8Bytes.Length, utf8Chars, 0);
string utf8String = new string(utf8Chars);
message.Body = utf8String;
// Build up the rest of the message
message.Cc = "(e-mail address removed)";
message.From = "(e-mail address removed)";
message.Subject = "Subject line";
message.To = "(e-mail address removed)";
But, this doesn't help either. Below is a small sampling of what
happens to the characters when I view them in my email client.
KTF ±ÂŸÀÓ ´Ü¸»±â º¸Çè¿¡ °¡ÀÔÇØ Áּż °¨»çµå¸³´Ï´Ù. º¸Çè ó¸®
´ÙÀ½´Ü°è·Î ³Ñ¾î°¡±â À§ÇÑ ÀýÂ÷´Â ´ÙÀ½°ú °°½À´Ï´Ù.
an email written in Korean using SMTP. When I send the message to an
Outlook client, everything works like a champ. But, when I send the
email to a web client, all the characters get screwed up and the email
is not legible. I figured the
System.Web.Mail.MailMessage.BodyEncoding property would control the
encoding of the characters, but, it doesn't seem to help. I've
included some code below:
System.Web.Mail.MailMessage message = new
System.Web.Mail.MailMessage();
// As far as I understand, Code Page 949 is for Korean Characters.
// I've also tried System.Text.Encoding.UTF8 to no avail.
message.BodyEncoding = System.Text.Encoding.GetEncoding(949);
message.BodyFormat = System.Web.Mail.MailFormat.Html;
// The body of the message is pulled from our SQL database.
// When comes in, the Korean characters look fine.
message.Body = "This is where my korean character formatted email will
go.";
message.Cc = "(e-mail address removed)";
message.From = "(e-mail address removed)";
message.Subject = "Subject line";
message.To = "(e-mail address removed)";
I can tell you, I've configured my browser to allow for Korean
characters. So, I don't suspect it is a browser problem. And, to add
complexity, when I compose my email message in Outlook and send it to
my web mail, the message is fine, it works like a champ. So,
therefore, I'm assuming I just don't understand something about
encoding strings. I also tried taking my string and converting to
UTF8 formatted string hoping that would help. I changed the code
above to the following:
System.Web.Mail.MailMessage message = new
System.Web.Mail.MailMessage();
// Need to convert the body string to UTF8
// The body of the message is pulled from our SQL database.
// When comes in, the Korean characters look fine.
string unicodeString = "This is where my korean character formatted
email will go.";
// Create two different encodings.
System.Text.Encoding utf8 = System.Text.Encoding.UTF8
System.Text.Encoding unicode = System.Text.Encoding.Unicode;
// Convert the string into a byte[].
byte[] unicodeBytes = unicode.GetBytes(unicodeString);
// Perform the conversion from one encoding to the other.
byte[] utf8Bytes = System.Text.Encoding.Convert(unicode, utf8,
unicodeBytes);
// Convert the new byte[] into a char[] and then into a string.
// This is a slightly different approach to converting to illustrate
// the use of GetCharCount/GetChars.
char[] utf8Chars = new char[utf8.GetCharCount(utf8Bytes, 0,
utf8Bytes.Length)];
utf8.GetChars(utf8Bytes, 0, utf8Bytes.Length, utf8Chars, 0);
string utf8String = new string(utf8Chars);
message.Body = utf8String;
// Build up the rest of the message
message.Cc = "(e-mail address removed)";
message.From = "(e-mail address removed)";
message.Subject = "Subject line";
message.To = "(e-mail address removed)";
But, this doesn't help either. Below is a small sampling of what
happens to the characters when I view them in my email client.
KTF ±ÂŸÀÓ ´Ü¸»±â º¸Çè¿¡ °¡ÀÔÇØ Áּż °¨»çµå¸³´Ï´Ù. º¸Çè ó¸®
´ÙÀ½´Ü°è·Î ³Ñ¾î°¡±â À§ÇÑ ÀýÂ÷´Â ´ÙÀ½°ú °°½À´Ï´Ù.