获取Outlook MailItem的内容类型 [英] Get the Content-Type of an Outlook MailItem

查看:193
本文介绍了获取Outlook MailItem的内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#开发Outlook VSTO,目标是Outlook2010.我需要获取消息的MIME内容类型(请考虑text/plain或其他更奇特的替代品).我唯一可以找到它的地方是消息标题,它是一个长字符串,我不想手动读取和解析.

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记录了 PidNameContentType 属性(备用链接),但我无法找到工作.这样的事情总是会失败(找不到).

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

另一方面,某些更常见"的标头(如urn:schemas:mailheader:subject)可以正常工作.

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

我只是使用PropertyAccessor错误吗? Outlook是否实际上不解析Content-Type标头,而我只需要手动执行它?还有其他方法可以获取此标头的内容吗?

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?

推荐答案

如何首先获取整个标头,然后搜索该字符串以获取所需的内容?

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);

来源:代码项目

这篇关于获取Outlook MailItem的内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆