开发者

nicely reading outlook mailitem properties

开发者 https://www.devze.com 2023-02-03 09:48 出处:网络
I am writing a plugin for outlook 2007 and i would like to read a property of a MailItem. I开发者_开发百科n particular i\'d like to know all the content-types of my attachments. Now the way i do this

I am writing a plugin for outlook 2007 and i would like to read a property of a MailItem.

I开发者_开发百科n particular i'd like to know all the content-types of my attachments. Now the way i do this now is something like this:

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

But I would much rather just call something like.

t.PropertyAccessor.GetProperty(PR_ATTACH_MIME_TAG);

I can't get that later option to work thou, however the property is mentioned that way in the msdn documentation. (http://msdn.microsoft.com/en-us/library/ms879575.aspx). Does anyone know how to nicely retrieve property's without using the string but the constant instead?


Recommended way of doing it is located 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);
0

精彩评论

暂无评论...
验证码 换一张
取 消