Get the Content-Type of an Outlook MailItem

六月ゝ 毕业季﹏ 提交于 2020-01-06 16:05:31

问题


I'm working on an Outlook VSTO in C#, targeting Outlook 2010. I need to get the MIME Content-Type of a message (think text/plain or its more exotic alternatives). The only place I can find this is in the message headers, which is a long string that I'd prefer not to need to read and parse manually.

MSDN documents the PidNameContentType property (alternate link), but I can't get it to work. Anything like that always fails (not found).

String ct = mail.PropertyAccessor.GetProperty(
    "urn:schemas:mailheader:content-type"); // Not found
String ct2 = mail.PropertyAccessor.GetProperty(
    "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/content-type"); // Not found

Weirdly, this even fails for a documented example that is similar:

String ct2 = mail.PropertyAccessor.GetProperty(
    "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/content-class"); // Not found

On the other hand, some of the "more common" headers, like urn:schemas:mailheader:subject, work fine.

Am I just using the PropertyAccessor wrong? Does Outlook not actually parse out the Content-Type header and I simply need to do it manually? Is there some other way to get this header's contents?


回答1:


Content-type of a message will be, well, message, right?

Take a look at the available properties with OutlookSpy (click IMessage) or MFCMAPI to see the available properties.




回答2:


How about getting the entire header first and then searching through that string to get what you need?

Const PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001E" 
Outlook.PropertyAccessor olPA = olkMsg.PropertyAccessor;
String Header = olPA.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS);

Source: Code Project



来源:https://stackoverflow.com/questions/38862470/get-the-content-type-of-an-outlook-mailitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!