Export (0) Print
Expand All

Creating and Sending Meeting Messages on Behalf of a Principal (Exchange Web Services)

Topic Last Modified: 2007-11-01

Starting with Microsoft Exchange Server 2007 Service Pack 1 (SP1), you can use delegate access to create and send a meeting invitation on behalf of a principal. Delegate permissions must be set before delegate access is enabled for an account. You can set delegate permissions by using Microsoft Office Outlook 2007, the Exchange Management Shell, or the Exchange Management Console.

Bb856541.note(en-us,EXCHG.80).gifNote:
To recipients of messages that are sent by a delegate on behalf of a principal, the sender appears as “Delegate on behalf of Principal.”
Delegates operate within their own mailboxes. Messages that are sent by delegates are saved in the delegate’s Sent Items folder.

The following code example shows how a delegate creates and sends a meeting on behalf of another user. In this example, user2 sends a meeting on behalf of user1. User2 is the delegate and user1 is the principal. User3 is a required attendee.

Setting delegate access permission is a prerequisite for this code example. For information about how to set delegate access permission, see Add- MailboxPermission.

static void CreateAndSendMeetingOnBehalfOfPrincipal()
{
    // Set the version, credentials, and the Client Access server on ExchangeServiceBinding.
    ExchangeServiceBinding esb = new ExchangeServiceBinding();
    esb.RequestServerVersionValue = new RequestServerVersion();
    esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2007_SP1;
    esb.Credentials = new NetworkCredential("user2", "password", "domain");
    esb.Url = "https://www.example.com/ews/exchange.asmx";

    // Create the request and specify how the item is handled.
    CreateItemType request = new CreateItemType();
    request.MessageDisposition = MessageDispositionType.SendAndSaveCopy;
    request.MessageDispositionSpecified = true;
    request.SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType.SendToAllAndSaveCopy;
    request.SendMeetingInvitationsSpecified = true;

    // Identify the principal's Calendar folder as the target folder for the calendar item.
    DistinguishedFolderIdType defCalendarFolder = new DistinguishedFolderIdType();
    defCalendarFolder.Id = DistinguishedFolderIdNameType.calendar;
    defCalendarFolder.Mailbox = new EmailAddressType();
    defCalendarFolder.Mailbox.EmailAddress = "user1@example.com";
    TargetFolderIdType target = new TargetFolderIdType();
    target.Item = defCalendarFolder;

    // Add the destination folder to the request.
    request.SavedItemFolderId = target;

    // Create the calendar item to start the meeting in one hour.
    CalendarItemType calendarItem = new CalendarItemType();
    calendarItem.Subject = "Delegate appointment";
    calendarItem.Body = new BodyType();
    calendarItem.Body.BodyType1 = BodyTypeType.Text;
    calendarItem.Body.Value = "This is the text of the delegate appointment.";
    calendarItem.Start = DateTime.Now.AddHours(1);
    calendarItem.StartSpecified = true;
    calendarItem.End = DateTime.Now.AddHours(2);
    calendarItem.EndSpecified = true;
    calendarItem.LegacyFreeBusyStatus = LegacyFreeBusyType.Busy;
    calendarItem.LegacyFreeBusyStatusSpecified = true;

    // Add attendee to calendar item.
    AttendeeType attendee1 = new AttendeeType();
    attendee1.Mailbox = new EmailAddressType();
    attendee1.Mailbox.EmailAddress = "user3@RERMAN-dom.extest.microsoft.com";
    calendarItem.RequiredAttendees = new AttendeeType[] { attendee1 };

    // Add the calendar item to the request.
    request.Items = new NonEmptyArrayOfAllItemsType();
    request.Items.Items = new ItemType[] { calendarItem };

    try
    {
        // Send the request and get the response.
        CreateItemResponseType response = esb.CreateItem(request);

        // Get the response messsages.
        ResponseMessageType[] rmta = response.ResponseMessages.Items;

        foreach (ResponseMessageType rmt in rmta)
        {
            ArrayOfRealItemsType itemArray = ((ItemInfoResponseMessageType)rmt).Items;
            ItemType[] items = itemArray.Items;

            // Get the item identifier for the meeting.
            foreach (ItemType item in items)
            {
                Console.WriteLine("Item identifier: " + item.ItemId.Id);
            }
        }
    }
    catch 
    {
        // Handle exception.
    }
}

User3 receives the meeting invitation. The Organizer and From properties of the meeting invitation are set with the principal's mailbox. The Sender property is set with the delegate's mailbox. The relationship between delegate and principal are expressed in Outlook Web Access 2007 as "[Sender property] on behalf of [From property]."

This code example was created by using proxy objects that are created by using Microsoft Visual Studio 2005 and Exchange Web Services in Exchange 2007 SP1.

Show:
© 2014 Microsoft