问题
When setting MailItem.HTMLBody
for a inline response, sometimes the updated body never gets displayed. If I make a call to MailItem.Save()
, sometimes it shows up but only under saved draft preview. Does anyone know of a way to force the updated HTMLBody to render?
Some addition findings:
- For emails with only plain text (but
MailItem.BodyFormat
isOlBodyFormat.olFormatHTML
), this always happens. - For emails with HTML content and images, this happens if user chooses to download external content when replying
- For emails with HTML content and images, this does NOT happen if user chooses not to download external content
I have tried to use different routes to get the MailItem through the explorer and they all lead to the same results. Here are the different methods I've tried, in case I missed anything:
- Through Outlook.Application.Explorers.NewExplorer event handler arg
- Through
ActiveInlineResponse
property
explorer = OutlookApp.ActiveExplorer();
response = explorer.ActiveInlineResponse;
- Through
InvokeMember("ActiveInlineResponse"...
explorer = OutlookApp.ActiveExplorer();
response = explorer.GetType().InvokeMember("ActiveInlineResponse", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public, null, explorer, null) as MailItem;
Environment:
- Office version: 16.0.10827.20118
- Windows 10
- Office 2007 Primary Interop
- VSTO 2010
回答1:
For those interested, I found what causes this behavior. It doesn't fully explain the underlying problem but at least we have a workaround.
Prior to setting HTMLBody, we accessed the document to retrieve selected text through Document doc = MailItem.GetInspector.WordEditor
.
Changing this to Document doc = ActiveExplorer.ActiveInlineResponseWordEditor
eliminated the issue described above.
来源:https://stackoverflow.com/questions/53010824/outlook-mailitem-htmlbody-doesnt-refresh-when-updated-under-inline-response