切换到宽版
  • 11855阅读
  • 5回复

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

上一主题 下一主题
 
只看楼主 倒序阅读 0楼  发表于: 2011-02-19

创建会议邀请:

1创建会议邀请邮件
2     public static void CreateAppointment(ExchangeServiceBinding esb)
3        {
4            // Create the appointment.
5            CalendarItemType appointment = new CalendarItemType();  
6            // Add item properties to the appointment.
7            appointment.Body = new BodyType();
8            appointment.Body.BodyType1 = BodyTypeType.Text;
9            appointment.Body.Value = "Agenda Items.";
10            //appointment.Categories = new string[] { "Category1", "Category2" };
11            appointment.Importance = ImportanceChoicesType.High;
12            appointment.ImportanceSpecified = true;
13            appointment.ItemClass = "IPM.Appointment";
14            appointment.Subject = "测试约会邮件";
15            // Add an attendee
16            EmailAddressType eat1 = new EmailAddressType();
17            eat1.EmailAddress = "第一个与会者邮箱地址";
18            eat1.Name = "姓名";
19            AttendeeType at1 = new AttendeeType();
20            at1.Mailbox = eat1;
21
22            EmailAddressType eat2 = new EmailAddressType();
23            eat2.EmailAddress = "第一二个与会者邮箱地址";
24            eat2.Name = "姓名";
25            AttendeeType at2 = new AttendeeType();
26            at2.Mailbox = eat2;
27
28            AttendeeType[] rAtt = new AttendeeType[2];
29            rAtt[0] = at1;
30            rAtt[1] = at2;
31[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            appointment.RequiredAttendees = rAtt;
32[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
33[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            //add meeting room attendee
34[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            EmailAddressType meetingRoom = new EmailAddressType();
35[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            meetingRoom.EmailAddress = "会议室邮箱地址";
36[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            meetingRoom.Name = "会议室名称";
37[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            AttendeeType meetingType = new AttendeeType();
38[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            meetingType.Mailbox = meetingRoom;
39[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            AttendeeType[] meetingTypeList = new AttendeeType[1];
40[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            meetingTypeList[0] = meetingType;
41[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            appointment.Resources = meetingTypeList;
42[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            appointment.Location = "会议地点";
43[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Add calendar properties to the appointment.
44[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            appointment.Start = System.DateTime.Parse("2009-05-25GMT14:00:00Z");
45[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            appointment.StartSpecified = true;
46[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            appointment.End = System.DateTime.Parse("2009-05-25GMT15:00:00Z");
47[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            appointment.EndSpecified = true;
48[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
49[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Identify the destination folder that will contain the appointment.
50[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            DistinguishedFolderIdType folder = new DistinguishedFolderIdType();
51[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            folder.Id = DistinguishedFolderIdNameType.calendar;
52[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
53[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Create the array of items that will contain the appointment.
54[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            NonEmptyArrayOfAllItemsType arrayOfItems = new NonEmptyArrayOfAllItemsType();
55[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            arrayOfItems.Items = new ItemType[1];
56[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
57[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Add the appointment to the array of items.
58[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            arrayOfItems.Items[0] = appointment;
59[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
60[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Create the CreateItem request.
61[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            CreateItemType createItemRequest = new CreateItemType();
62[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // The SendMeetingInvitations attribute is required for calendar items.
63[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            //createItemRequest.SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendToNone;
64[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            createItemRequest.SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendToAllAndSaveCopy;
65[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            createItemRequest.SendMeetingInvitationsSpecified = true;
66[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Add the destination folder to the CreateItem request.
67[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            createItemRequest.SavedItemFolderId = new TargetFolderIdType();
68[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            createItemRequest.SavedItemFolderId.Item = folder;
69[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Add the items to the CreateItem request.
70[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            createItemRequest.Items = arrayOfItems;
71[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            try
72[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]            {
73[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                // Send the request and get the response.
74[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                CreateItemResponseType createItemResponse = esb.CreateItem(createItemRequest);
75[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                // Get the response messages.
76[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                ResponseMessageType[] rmta = createItemResponse.ResponseMessages.Items;
77[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                foreach (ResponseMessageType rmt in rmta)
78[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]                {
79[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                    ArrayOfRealItemsType itemArray = ((ItemInfoResponseMessageType)rmt).Items;
80[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                    ItemType[] items = itemArray.Items;
81[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
82[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                    // Get the item identifier and change key for each item.
83[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                    foreach (ItemType item in items)
84[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]                    {
85[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                        Console.WriteLine("Item identifier: " + item.ItemId.Id);
86[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                        Console.WriteLine("Item change key: " + item.ItemId.ChangeKey);
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/InBlock.gif[/img]            catch (Exception e)
91[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]            {
92[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                Console.WriteLine("Error Message: " + e.Message);
93[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif[/img]            }

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

应答会议邀请:

1[img]http://www.cnblogs.com/Images/OutliningIndicators/None.gif[/img]应答会议邀请
2[img]http://www.cnblogs.com/Images/OutliningIndicators/None.gif[/img]   public static void AcceptItem(ExchangeServiceBinding esb,string meetingID)
3[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif[/img]         {
4[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Create the request.
5[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            CreateItemType request = new CreateItemType();
6[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
7[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Set the message disposition on the request.
8[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.MessageDisposition = MessageDispositionType.SendAndSaveCopy;
9[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.MessageDispositionSpecified = true;
10[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            
11[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Create the AcceptItem response object.
12[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            AcceptItemType acceptItem = new AcceptItemType();
13[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
14[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Identify the meeting request to accept.
15[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            acceptItem.ReferenceItemId = new ItemIdType();
16[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            acceptItem.ReferenceItemId.Id = meetingID;
17[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
18[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Add the AcceptItem response object to the request.
19[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.Items = new NonEmptyArrayOfAllItemsType();
20[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.Items.Items = new ItemType[1];
21[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.Items.Items[0] = acceptItem;          
22[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Send the request and get the response.
23[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            CreateItemResponseType response = esb.CreateItem(request);
24[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
25[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            ArrayOfResponseMessagesType aormt = response.ResponseMessages;
26[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            ResponseMessageType[] rmta = aormt.Items;
27[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            foreach (ResponseMessageType rmt in rmta)
28[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]            {
29[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                ItemInfoResponseMessageType iirmt = (rmt as ItemInfoResponseMessageType);
30[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                if (iirmt.ResponseClass == ResponseClassType.Success)
31[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]                {
32[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                    Console.WriteLine("Successfully accepted meeting");
33[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif[/img]                }

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

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

分享到
只看该作者 1楼  发表于: 2011-03-09
exchange 2010 的开发教程有吗。
只看该作者 2楼  发表于: 2012-09-23
代码有点乱啊
只看该作者 3楼  发表于: 2012-10-09
学习下
只看该作者 4楼  发表于: 2012-11-23
在吗,问个问题。我写了几行代码,别人能收到会议邀请,但是本人的日历中不显示。不知道是怎么回事?

  //  Appointment appointment = new Appointment(_service);//约会主题
  //      appointment.Subject = "Play Basketball";//约会内容
  //      appointment.Body = "Play Basketball";//约会开始时间2010-6-1 12:30:00
  //      appointment.Start = new DateTime(2012,11,22,13,20,0);//约会结束
  //      appointment.End = appointment.Start.AddHours(2);//约会的位置
  
  //      appointment.Location = "蓝罐会议室";
        
  //      appointment.RequiredAttendees.Add("bennyzhang@rich.com");
        
  //     // appointment.RequiredAttendees.Add("rcao@rich.com");
    
  //      appointment.Save( SendInvitationsMode.SendToAllAndSaveCopy);
只看该作者 5楼  发表于: 2013-02-20
快速回复
限60 字节
 
上一个 下一个