.NET Framework Bookmark and Share   
 index > Network Class Library (System.Net) > MailMessage.SubjectEncoding
 

MailMessage.SubjectEncoding

Hi
I'm trying to send a mail thru System.Net.Mail and I want it to use UTF-8 encoding for the Subject. So I tried this:
MailMessagemail=newMailMessage(from,to);
mail.SubjectEncoding=Encoding.UTF8;
mail.Subject="åäö";
mail.BodyEncoding=Encoding.UTF8;
mail.Body=body;
mail.IsBodyHtml=htmlmode;
SmtpClientsmtp=newSmtpClient();
smtp.Send(mail);
But the result was: ï¿?ï¿?ï¿?/font>
So I took a look at the System.Net code and found the EncodeHeaderValue method in the System.Net.Mime.MimeBasePart class.
And in there I noticed two things, it starts of by creating the 'encoded-word' string. And if base64 encoding is used it does this.
Base64Streamstream=newBase64Stream(-1);
stream.EncodeBytes(bytes,0,bytes.Length,true);
builder.Append(Encoding.ASCII.GetString(stream.WriteState.Buffer,0,stream.WriteState.Length));

So I wonder:
1. Should it really use Encoding.ASCII.GetString()? Shouldn't it be using the selected encoding, for example Encoding.UTF8.GetString().
2. An 'encoded-word' word can only be 75 characters long, including 'charset', 'encoding' and 'encoded-text'. But I can't figure out how you are creating multiple 'encoded-word's if needed.
3. Can any of the above cause the problem I'm having?
Thanks
Encoded-word specification: http://www.faqs.org/rfcs/rfc2047.html
  •  
masterofX
After a lot of investigation and working with the customer, we believe that the SubjectEncoding is working correctly as the behavior is working correctly with several email clients, however the behavior was noticed in windows live mail, so it's possible that there is an issue with that program. Information on that behavior has been forwarded to the live mail team for investigation. Please let me know if you experience any additional problems. Thanks
Jeff_Tucker_NCL
I'm looking at how SmtpClient handles creating encoded-word subject headers. I'll reply once I have more information.
Jeff_Tucker_NCL
After a lot of investigation and working with the customer, we believe that the SubjectEncoding is working correctly as the behavior is working correctly with several email clients, however the behavior was noticed in windows live mail, so it's possible that there is an issue with that program. Information on that behavior has been forwarded to the live mail team for investigation. Please let me know if you experience any additional problems. Thanks
Jeff_Tucker_NCL

You can use google to search for other answers

Custom Search

More Threads

• Question about NetworkStream.BeginRead() and NetworkStream.EndRead()
• System.Net support on winmo 6.x
• AS2 Message Decryption Failed
• Developing a Lan crawler
• Why the delayed response when an invalid hostname is sent to the DNS server?
• Welcome to the forum!
• How to specify notification (bounce) mails reciever
• SocketAsyncEventArgs.BytesTransferred accumulates to 24820 when SendAsync is completed without receiver
• Server-client discovery without port forwarding
• IPAddress.Parse question.