切换到宽版
  • 8754阅读
  • 1回复

[分享]Exchange Server 2007 二次开发 (七) [复制链接]

上一主题 下一主题
 
只看楼主 倒序阅读 0楼  发表于: 2011-02-19
关键词: 服务器exchange
获取收件箱中邮件,有两种方式,GetItemType和FindItemType,通过FindItemType只能得到邮件的一部分属性,如标题、正文、发件人姓名等等,而像发件人地址、会议邀请邮件的会议地点、开始时间结束时间等只能通过GetItemType来获得,GetItemType能得到邮件的所有属性:
1读取会议邮件
2  public static void GetMeetingMailMessage(ExchangeServiceBinding exchangeServer)
3        {
4              DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
5            folderIDArray[0] = new DistinguishedFolderIdType();
6            folderIDArray[0].Id = DistinguishedFolderIdNameType.inbox;
7
8            PathToUnindexedFieldType ptuftDisplayName = new PathToUnindexedFieldType();
9            ptuftDisplayName.FieldURI = UnindexedFieldURIType.folderDisplayName;
10
11            PathToExtendedFieldType pteftComment = new PathToExtendedFieldType();
12            pteftComment.PropertyTag = "0x3004"; // PR_COMMENT
13            pteftComment.PropertyType = MapiPropertyTypeType.String;
14
15             GetFolderType myfoldertype = new GetFolderType();
16            myfoldertype.FolderIds = folderIDArray;
17            myfoldertype.FolderShape = new FolderResponseShapeType();
18            myfoldertype.FolderShape.BaseShape = DefaultShapeNamesType.IdOnly;
19            myfoldertype.FolderShape.AdditionalProperties = new BasePathToElementType[2];
20            myfoldertype.FolderShape.AdditionalProperties[0] = ptuftDisplayName;
21            myfoldertype.FolderShape.AdditionalProperties[1] = pteftComment;
22
23             GetFolderResponseType myFolder = exchangeServer.GetFolder(myfoldertype);
24
25
26             FolderInfoResponseMessageType firmtInbox =
27                (FolderInfoResponseMessageType)myFolder.ResponseMessages.Items[0];
28
29            PathToUnindexedFieldType ptuftSubject = new PathToUnindexedFieldType();
30            ptuftSubject.FieldURI = UnindexedFieldURIType.itemSubject;
31[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
32[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            PathToUnindexedFieldType ptuftBody = new PathToUnindexedFieldType();
33[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            ptuftBody.FieldURI = UnindexedFieldURIType.itemAttachments;
34[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
35[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            PathToExtendedFieldType pteftFlagStatus = new PathToExtendedFieldType();
36[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            pteftFlagStatus.PropertyTag = "0x1090"; // PR_FLAG_STATUS
37[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            pteftFlagStatus.PropertyType = MapiPropertyTypeType.Integer;
38[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
39[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
40[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]              FindItemType findItemRequest = new FindItemType();
41[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            findItemRequest.Traversal = ItemQueryTraversalType.Shallow;
42[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            findItemRequest.ItemShape = new ItemResponseShapeType();
43[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            findItemRequest.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;
44[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
45[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
46[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            findItemRequest.ParentFolderIds = new FolderIdType[1];
47[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            findItemRequest.ParentFolderIds[0] = firmtInbox.Folders[0].FolderId;
48[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
49[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // 获取邮件
50[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]              FindItemResponseType firt = exchangeServer.FindItem(findItemRequest);
51[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
52[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // 循环迭代每一封邮件
53[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]        
54[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]              foreach (FindItemResponseMessageType firmtMessage in firt.ResponseMessages.Items)
55[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]            {
56[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                // 如果包含邮件,显示出来
57[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                  if (firmtMessage.RootFolder.TotalItemsInView > 0)
58[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]                {
59[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                    // 循环迭代每一封邮件详细信息
60[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                    foreach (ItemType it in ((ArrayOfRealItemsType)firmtMessage.RootFolder.Item).Items)
61[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]                    {  
62[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                        //会议邀请邮件
63[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                        if (it.ItemClass == "IPM.Schedule.Meeting.Request")
64[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]                        {
65[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            // 通过GetItemType对象来得到邮件的正文
66[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                                GetItemType getItemRequest = new GetItemType();
67[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            // 设置必要的属性
68[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                                getItemRequest.ItemIds = new BaseItemIdType[1];
69[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            getItemRequest.ItemIds[0] = (BaseItemIdType)it.ItemId;
70[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            getItemRequest.ItemShape = new ItemResponseShapeType();
71[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            getItemRequest.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;
72[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            getItemRequest.ItemShape.IncludeMimeContent = true;
73[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
74[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            // 获得服务器的相应
75[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                                GetItemResponseType getItemResponse = exchangeServer.GetItem(getItemRequest);
76[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
77[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            // 得到邮件体
78[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                                ItemInfoResponseMessageType getItemResponseMessage =
79[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                                                  getItemResponse.ResponseMessages.Items[0] as
80[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                                                  ItemInfoResponseMessageType;
81[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
82[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            Mail.ews.MeetingRequestMessageType meeting = getItemResponseMessage.Items.Items[0] as Mail.ews.MeetingRequestMessageType;
83[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
84[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            Console.WriteLine(meeting.Subject);
85[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            Console.WriteLine(meeting.From.Item.EmailAddress);
86[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif[/img]                        }

87[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif[/img]                    }

88[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif[/img]                }

89[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif[/img]            }

90[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif[/img]        }

分享到
只看该作者 1楼  发表于: 2011-03-09
这些章节对我来讲真是非常有用啊。
快速回复
限60 字节
 
上一个 下一个