How to: Automatically Accept a Meeting Request

This example shows how to use the Respond(OlMeetingResponse, Object, Object) method to automatically accept a meeting request.

Programming Applications for Office Outlook 2007

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007, from Microsoft Press (ISBN 9780735622494, copyright Microsoft Press 2007, all rights reserved).

Buy this book

Sample chapters

A MeetingItem object represents a request to add an appointment, represented by an AppointmentItem object, to a recipient’s calendar. To respond to a meeting request, use the GetAssociatedAppointment(Boolean) method to obtain the AppointmentItem associated with the meeting request. Then use the Respond(OlMeetingResponse, Object, Object) method of the AppointmentItem to notify the meeting organizer whether the meeting has been accepted, declined, or tentatively added to the recipient’s calendar. The Respond method accepts three parameters. The Response parameter indicates whether the response is accept, decline, or tentative. The fNoUI and fAdditionalTextDialog parameters are bool values that determine whether a response will be sent, and whether the user may or may not edit the response, respectively. In the following code example, AutoAcceptMeetingRequests enumerates through every MeetingItem object to get the associated AppointmentItem. AutoAcceptMeetingRequests then uses the Respond method with the fNoUI parameter set to true to indicate that a response will be sent automatically to accept the meeting request.

If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void AutoAcceptMeetingRequests()
{
    Outlook.MeetingItem mtgResponse;
    Outlook.Folder folder = Application.Session.
        GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
        as Outlook.Folder;
    string filter = "[MessageClass] = " +
        "'IPM.Schedule.Meeting.Request'";
    Outlook.Items items = folder.Items.Restrict(filter);
    foreach (Outlook.MeetingItem request in items)
    {
        Outlook.AppointmentItem appt =
            request.GetAssociatedAppointment(true);
        if (appt != null)
        {
            mtgResponse = appt.Respond(
                Outlook.OlMeetingResponse.olMeetingAccepted,
                true, Type.Missing);
            mtgResponse.Send();
        }
    }
}

Other resources

Show:
© 2014 Microsoft