c# - 很好地阅读 outlook mailitem 属性

标签 c# outlook-addin office-2007 mapi

我正在为 outlook 2007 编写插件,我想读取 MailItem 的属性。

特别是我想知道我的附件的所有内容类型。现在我这样做的方式是这样的:

Outlook.MailItem item = OutlookItem as Outlook.MailItem;
Outlook.Attachments itt = item.Attachments;

foreach (Outlook.Attachment t in item.Attachments)
{
textBox1.Text += t.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001F");
}

但我更愿意只调用类似的东西。

t.PropertyAccessor.GetProperty(PR_ATTACH_MIME_TAG);

我无法让以后的选项起作用,但是在 msdn 文档中以这种方式提到了该属性。 (http://msdn.microsoft.com/en-us/library/ms879575.aspx)。有谁知道如何在不使用字符串而是使用常量的情况下很好地检索属性?

最佳答案

推荐的做法位于 here:

// C#
// Outlook 2007
// PropertyAccessor usage sample for MailItem.Attachments[n]
////////////////////////////////////////////
// For all those MAPI tags related to an Outlook Mailitem, they're all on the link:
//ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/mapi/html/af87aa9c-02f9-4b2c-9c7b-0fa1ea27af02.htm
// go there, then synch the index to see the full list at your disposal
// if you have the Outlook developer's reference loaded.
//
// of note for attachments:
//
//PR_ATTACH_ADDITIONAL_INFO     0x370F0102 
//PR_ATTACH_CONTENT_BASE        0x3711001E (0x3711001F for Unicode) 
//PR_ATTACH_CONTENT_ID          0x3712001E (0x3712001F for Unicode) 
//PR_ATTACH_CONTENT_LOCATION    0x3713001E (0x3713001F for Unicode) 
//PR_ATTACH_DATA_BIN            0x37010102 The PR_ATTACH_DATA_BIN property holds the attachment when the value of the PR_ATTACH_METHOD property is ATTACH_BY_VALUE, which is the usual attachment method and the only one required to be supported.
//PR_ATTACH_DATA_OBJ            0x3701000D The PR_ATTACH_DATA_OBJ property holds the attachment when the value of the PR_ATTACH_METHOD property is ATTACH_EMBEDDED_MSG 
//PR_ATTACH_ENCODING            0x37020102 identifies the algorithm used to transform the data in an attachment. (see PR_ATTACH_TAG
//PR_ATTACH_EXTENSION           0x3703001E (0x3703001F for Unicode) The receiving client should first check for PR_ATTACH_EXTENSION, and if it is not provided, should parse the filename extension from the attachment's PR_ATTACH_FILENAME or PR_ATTACH_LONG_FILENAME property.
//PR_ATTACH_FILENAME            0x3704001E (0x3704001F for Unicode) 8.3 naming
//PR_ATTACH_FLAGS               0x37140003 PT_LONG ATT_INVISIBLE_IN_HTML |ATT_INVISIBLE_IN_RTF 
//PR_ATTACH_LONG_FILENAME       0x3707001E (0x3707001F for Unicode)  Platforms that support long filenames should set both the PR_ATTACH_LONG_FILENAME and PR_ATTACH_FILENAME properties when sending, and should check PR_ATTACH_LONG_FILENAME first when receiving. 
//PR_ATTACH_LONG_PATHNAME       0x370D001E (0x370D001F for Unicode)
//PR_ATTACH_METHOD              0x37050003 PT_LONG 
//      NO_ATTACHMENT           - When created, all attachment objects have an initial PR_ATTACH_METHOD value of NO_ATTACHMENT
//      ATTACH_BY_VALUE         - PR_ATTACH_DATA_BIN contains attachment data
//      ATTACH_BY_REFERENCE     - common path accessible by sender & recipient (common file server) via PR_ATTACH_PATHNAME or PR_ATTACH_LONG_PATHNAME
//      ATTACH_BY_REF_RESOLVE   - full path)
//      ATTACH_BY_REF_ONLY      -  
//      ATTACH_EMBEDDED_MSG     - PR_ATTACH_DATA_OBJ contains the object that supports IMessage interface
//      ATTACH_OLE  
//PR_ATTACH_MIME_SEQUENCE       0x37100003 PT_LONG
//PR_ATTACH_MIME_TAG            0x370E001E (0x370E001F for Unicode) 
//PR_ATTACH_NUM                 0x0E210003 PT_LONG
//PR_ATTACH_PATHNAME            0x3708001E (0x3708001F for Unicode) 8.3 and limit of 256 characters total
//PR_ATTACH_RENDERING           0x37090102 PT_BINARY For an attached file, PR_ATTACH_RENDERING usually portrays an icon for the file. 
//                              - but see ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/mapi/html/be29f536-a402-4e5e-b06d-9a7af587d719.htm
//PR_ATTACH_SIZE                0x0E200003 PT_LONG
//PR_ATTACH_TAG                 0x370A0102 identifies the application that originally generated the attachment
//PR_ATTACH_TRANSPORT_NAME      0x370C001E (0x370C001F for Unicode) used by TNEF and proansport provider -  It is usually not available to client applications. 
//PR_ATTACHMENT_X400_PARAMETERS 0x37000102 UNSUPPORTED, DO NOT USE
//


// assume you have an Outlook.MailItem:
// also assume that you're working on attachment # 'x' 
// btw for newbies, attachment
// set up the schema paths
string SchemaPR_ATTACH_METHOD = @"http://schemas.microsoft.com/mapi/proptag/0x37050003";
string SchemaPR_ATTACH_CONTENT_ID = @"http://schemas.microsoft.com/mapi/proptag/0x3712001E";

Outlook.PropertyAccessor oPA = mailItem.Attachments[x].PropertyAccessor;
string AttachMethod = (string)oPA.GetProperty(SchemaPR_ATTACH_METHOD);
string AttachCID = (string)oPA.GetProperty(SchemaPR_ATTACH_CONTENT_ID);

关于c# - 很好地阅读 outlook mailitem 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4657684/

相关文章:

c# - SQL Server 日志文件使用 Hangfire 增长了 40GB

deployment - 是否可以在没有 Office 2007 的情况下部署 Office 2007 PIA?

sql-server-2008 - Visual Studio 2010 与 SQL Server 2008 和 Office 2007 的正确安装顺序?

c# - 在一个应用程序中使用 dapper 和 MongoDb 是否正确

c# - Windows 匿名管道上的非阻塞 io

outlook - 如何在Outlook COM/VSTO和Office JS加载项之间共享用户漫游设置

vsto - 删除收件人时未触发 Outlook 2007 属性更改

c# - ItemSend 事件未触发

vba - Excel 2007 VBA - 使用 Sheets.Add 在工作簿末尾创建图表

c# - 将数字 [n] 0-9 转换为键盘 Shift+[n] 字符