很好地阅读outlook mailitem属性

时间:2011-01-11 12:39:05

标签: 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)。有没有人知道如何在不使用字符串而是使用常量的情况下很好地检索属性?

1 个答案:

答案 0 :(得分:11)

推荐的方法是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);