You tape line with:
mail.HTMLBody = mail.Body;
You should use
mail.HTMLBody = "your html <b>code</b>"
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This seems to start happening out of no where since May this year to the desktop version of Outlook, almost looks like a bug from some recent update that Microsoft is rolling out.
So I have the following simple code to reproduce this problem:
var app = new Application();
var session = app.Session;
var mail = (MailItem)session.GetItemFromID("0000");
// mail.BodyFormat is olBodyFormat.Plain
// setting it to olFormatHTML corrupts the email body
mail.BodyFormat = OlBodyFormat.olFormatHTML;
// after setting the body format to olFormatHTML, the body format remains olBodyFormat.Plain
The email body text after trying to set the body format to HTML changes to incorrect Unicode characters.
The following code achieves the same result:
var app = new Application();
var session = app.Session;
var mail = (MailItem)session.GetItemFromID("00000");
mail.HTMLBody = mail.Body;
If the plain text body was "asdf" and the email body encoding is Western European (Windows), i.e. InternetCodepage = 20127
, it converts the text to "獡晤".
At first I thought this could be a page encoding problem so I tried the following code:
var app = new Application();
var session = app.Session;
var mail = (MailItem)session.GetItemFromID("00000");
mail.InternetCodepage = 65001; // sets the email encoding to UTF-8
mail.HTMLBody = mail.Body;
Yet the same thing still happens.
Does anyone know where I can report this bug to Microsoft?
You tape line with:
mail.HTMLBody = mail.Body;
You should use
mail.HTMLBody = "your html <b>code</b>"
I am having a similar problem - accessing the email using the Interop.Outlook library. We have an application the processes the email and appends a message to the bottom of the email. Just recently, quite a few users who are on the latest version of Outlook are reporting that some emails, after being processed, get garbled chinese characters.
Stepping through the debugger, it occurs the moment I either update HTMLBody of the email with additional text (we are ensuring that the html is valid) or create a copy of the email. This application has been working for the last 10 years without any changes.
_mail.HTMLBody = newHTmlBody;
Any idea on how to fix this?
That is not a similar I think.
If you have deferent characters in newHTmlBody, then you should change Encoding your file.
In vb.net is simple, you should change System.IO.StreamWriter from Default to UTF8 or Unicode
In VBA you should find right function to change Encoding
or you should change format your source file.
Regards