Pieter van der Westhuizen

Sending and updating Outlook Calendar’s appointments and meeting requests

2015 is here, and from all of us at Add-in Express we wish you a very prosperous year. We’ll kick off this year by taking a closer look at Microsoft Outlook appointments and meetings.

Difference between Outlook appointments and meetings

In essence the Outlook Appointment and Meeting objects are the same thing. A meeting is an appointment scheduled by inviting attendees whereas an appointment is an entry on the users’ calendar that is set for a specific date and time.

The Outlook AppointmentItem can be a meeting, an event or recurring meetings or events. A meeting that is sent to other users arrives in their Inbox as an Outlook MeetingItem. If the user accepts the meeting request it is saved as an AppointmentItem in the users’ Outlook calendar.

The following examples were created using Add-in Express for Office and .NET. All of the code samples are written in C#, which is my language of choice, but you are free to use VB.NET or Visual C++.NET as well.

Creating an Outlook appointment programmatically

In the following code, we’ll create a basic appointment in our Outlook calendar by using the CreatItem method of the Outlook Application object.

private void adxCreateAppointmentRibbonButton_OnClick(object sender, IRibbonControl control, bool pressed)
    {
        Outlook.AppointmentItem appointment = null;
        try
        {
            appointment = (Outlook.AppointmentItem)OutlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem);
            appointment.Start = new DateTime(2015, 01, 25, 13, 30, 00);
            appointment.End = new DateTime(2015, 01, 25, 15, 30, 00);
            appointment.Subject = "Drink Coffee";
            appointment.Location = "Bob's Donut Shop";
            appointment.Body = "Go have some coffee and a donut at Bob's";
            appointment.BusyStatus = Outlook.OlBusyStatus.olOutOfOffice;
            appointment.Save();
        }
        finally
        {
            if (appointment != null) Marshal.ReleaseComObject(appointment);
        }
    }

Note that we set both the Start and End properties to DateTime object. You also have the option to only set the Start property and then specify the Duration property. The Duration property accepts an integer value which is the duration of the appointment in minutes.

In the following code, we’ll schedule the same appointment in Outlook, but this time we’ll set the Duration to 2 hours.

private void adxCreateAppointmentRibbonButton_OnClick(object sender, IRibbonControl control, bool pressed)
    {
        Outlook.AppointmentItem appointment = null;
        try
        {
            appointment = (Outlook.AppointmentItem)OutlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem);
            appointment.Start = new DateTime(2015, 01, 25, 13, 30, 00);
            appointment.Duration = 120;
            appointment.Subject = "Drink Coffee";
            appointment.Location = "Bob's Donut Shop";
            appointment.Body = "Go have some coffee and a donut at Bob's";
            appointment.BusyStatus = Outlook.OlBusyStatus.olOutOfOffice;
            appointment.Save();
        }
        finally
        {
            if (appointment != null) Marshal.ReleaseComObject(appointment);
        }
    }

Creating a reminder for an appointment in Outlook

In order to create a reminder for an Outlook appointment, we can create the appointment in a similar way as we’ve done previously and set the ReminderSet property to True. The ReminderMinutesBeforeStart is a Long value that sets the amount of minutes before the appointment to show the reminder.

In the following example, we’ll schedule a new appointment and set the Outlook calendar to remind us 30 minutes before the appointment.

private void adxAppointmentWithReminderRibbonButton_OnClick(object sender, IRibbonControl control, bool pressed)
    {
        Outlook.AppointmentItem appointment = null;
        try
        {
            appointment = (Outlook.AppointmentItem)OutlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem);
            appointment.Start = new DateTime(2015, 01, 20, 10, 00, 00);
            appointment.End = new DateTime(2015, 01, 20, 11, 00, 00);
            appointment.ReminderSet = true;
            appointment.ReminderMinutesBeforeStart = 30;
            appointment.Subject = "Dentist Visit";
            appointment.Location = "Medical Building, 123 West Street";
            appointment.Save();
        }
        finally
        {
            if (appointment != null) Marshal.ReleaseComObject(appointment);
        }
    }

Creating recurring appointments in Outlook calendar

Recurring appointments in Outlook are appointments that happen on a regular basis. In order to create a recurring Outlook appointment we need to use the RecurrencePattern property of the Appointment item. In the following code, we’ll create a new appointment that occurs every Tuesday and Friday.

private void adxRecurringAppointmentRibbonButton_OnClick(object sender, IRibbonControl control, bool pressed)
    {
        Outlook.AppointmentItem appointment = null;
        Outlook.RecurrencePattern recurrencePattern = null;
        try
        {
            appointment = (Outlook.AppointmentItem)OutlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem);
            recurrencePattern = appointment.GetRecurrencePattern();
            recurrencePattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursWeekly;
            recurrencePattern.DayOfWeekMask = Outlook.OlDaysOfWeek.olTuesday | Outlook.OlDaysOfWeek.olFriday;
            recurrencePattern.PatternStartDate = new DateTime(2015, 01, 13);
            recurrencePattern.PatternEndDate = new DateTime(2015, 03, 20);
            recurrencePattern.StartTime = new DateTime(2015, 01, 13, 8, 0, 0);
            recurrencePattern.EndTime = new DateTime(2015, 03, 20, 8, 0, 0);
            recurrencePattern.Duration = 30;
            appointment.Subject = "Project stand up meeting";
            appointment.Save();
        }
        finally
        {
            if (appointment != null) Marshal.ReleaseComObject(appointment);
            if (recurrencePattern != null) Marshal.ReleaseComObject(recurrencePattern);
        }
    }

Creating and sending an Outlook meeting request

To create a new meeting request in the Outlook calendar, we’ll create a new appointment item and add recipients to the appointment items’ Recipients collection. Recipients are added using the Add method, which accepts a string parameter with the contact name to invite to the meeting.

If a recipient is added to the Recipients collection that does not exist in the Outlook address book an exception will be thrown. In order to avoid this you can use the Resolve method of the Recipient item or the ResolveAll method of the Recipients collection.

In the following code, we’ll create a new Outlook meeting request and invite one attendee after resolving their name.

private void adxCreateMeetingRibbonButton_OnClick(object sender, IRibbonControl control, bool pressed)
    {
        Outlook.AppointmentItem appointment = null;
        Outlook.Recipients recipients = null;
        Outlook.Recipient recipient = null;
 
        try
        {
            appointment = (Outlook.AppointmentItem)OutlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem);
            appointment.Subject = "A meeting";
            appointment.Start = DateTime.Now.AddHours(1);
            appointment.Duration = 60;
            appointment.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;
            recipients = appointment.Recipients;
            recipient = recipients.Add("Alfred Smith");
            recipient.Type = (int)Outlook.OlMeetingRecipientType.olRequired;
            if (recipient.Resolve())
            appointment.Send();
        }
        finally
        {
            if (recipient != null) Marshal.ReleaseComObject(recipient);
            if (recipients != null) Marshal.ReleaseComObject(recipients);
            if (appointment != null) Marshal.ReleaseComObject(appointment);
        }
    }

Showing the Check named dialog to manually resolve recipients

If the recipient cannot be resolved using the Resolve method, you can use the SelectNamesDialog to manually resolve the recipient. In the following code, we’ll create a new Outlook appointment and add recipients. We’ll then loop through the recipients and if the recipient cannot be resolved we’ll show the SelectNames Dialog so that the user can manually choose the recipients.

private void adxCheckNamesDialogRibbonButton_OnClick(object sender, IRibbonControl control, bool pressed)
    {
        Outlook.NameSpace nameSpace = null;
        Outlook.AppointmentItem appointment = null;
        Outlook.Recipients recipients = null;
        Outlook.Recipient recipient1 = null;
        Outlook.Recipient recipient2 = null;
        Outlook.SelectNamesDialog selectDialog = null;
        Outlook.Recipients selectDialogRecipients = null;
 
        try
        {
            nameSpace = OutlookApp.Session;
            appointment = (Outlook.AppointmentItem)OutlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem);
            appointment.Subject = "A meeting";
            appointment.Start = DateTime.Now.AddHours(1);
            appointment.Duration = 60;
            appointment.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;
            recipients = appointment.Recipients;
 
            recipient1 = recipients.Add("Alfred Smith");
            recipient1.Type = (int)Outlook.OlMeetingRecipientType.olRequired;
 
            recipient2 = recipients.Add("Unknown Contact");
            recipient2.Type = (int)Outlook.OlMeetingRecipientType.olOptional;
 
            for (int i = 1; i <= recipients.Count; i++)
            {
                Outlook.Recipient recipient = recipients[i];
                if (!recipient.Resolve())
                {
                    selectDialog = nameSpace.GetSelectNamesDialog();
                    selectDialogRecipients = selectDialog.Recipients;
 
                    recipients.Remove(i);
                    selectDialog.Display();
                    if (selectDialogRecipients.ResolveAll())
                    {
                        recipients.Add(recipient.Name);
                    }
                    else
                    {
                        recipients.Remove(i);
                    }
 
                }
                if (recipient != null) Marshal.ReleaseComObject(recipient);
            }
        }
        finally
        {
            if (selectDialogRecipients != null) Marshal.ReleaseComObject(selectDialogRecipients);
            if (selectDialog != null) Marshal.ReleaseComObject(selectDialog);
            if (recipient2 != null) Marshal.ReleaseComObject(recipient2);
            if (recipient1 != null) Marshal.ReleaseComObject(recipient1);
            if (recipients != null) Marshal.ReleaseComObject(recipients);
            if (appointment != null) Marshal.ReleaseComObject(appointment);
            if (nameSpace != null) Marshal.ReleaseComObject(nameSpace);
        }
    }

Responding to an Outlook meeting request programmatically

To programmatically respond to a meeting request (i.e. accept or decline it), you will first need to check if the item is an Outlook MeetingItem. You can then use the GetAssociatedAppointment method to get the Outlook AppointmentItem that is associated with the meeting request and respond to the request by invoking the Respond method.

In the following code, we'll loop through the current selection in the Outlook Explorer and will check if the items are Outlook MeetingItems. If the item is a MeetingItem, we'll get the AppointmentItem that is associated with the meeting and accept it using the Resolve method.

private void adxAcceptMeetingRibbonButton_OnClick(object sender, IRibbonControl control, bool pressed)
    {
        Outlook.Explorer currExplorer = null;
        Outlook.Selection selection = null;
 
        try
        {
            currExplorer = OutlookApp.ActiveExplorer();
            selection = currExplorer.Selection;
 
            for (int i = 1; i <= selection.Count; i++)
            {
                if (selection[i] is Outlook.MeetingItem)
                {
                    Outlook.MeetingItem meeting = selection[i] as Outlook.MeetingItem;
                    Outlook.AppointmentItem appointment = meeting.GetAssociatedAppointment(true);
                    if (appointment != null)
                    {
                        appointment.Respond(Outlook.OlMeetingResponse.olMeetingAccepted, true);
                        Marshal.ReleaseComObject(appointment);
                    }
                    Marshal.ReleaseComObject(meeting);
                }
            }
        }
        finally
        {
            if (selection != null) Marshal.ReleaseComObject(selection);
            if (currExplorer != null) Marshal.ReleaseComObject(currExplorer);
        }
    }

Thank you for reading. Until next time, keep coding!

Available downloads:

This sample Outlook add-in was developed using Add-in Express for Office and .net:

Outlook Appointments sample add-in (C#)

18 Comments

  • https://secure.gravatar.com/avatar/8fe9449cade7b11cd48d1d080e7870bf?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G SharePoint Developer says:

    Hi; I was trying to create a meeting request as shown in the code snippets. Is “OutlookApp” a custom class that you’ve created. I couldnt find it under the Microsoft.Office.interop.Outlook namespace. Thanks.

  • https://secure.gravatar.com/avatar/e1a4c2b21a5186e0b27c1c601f418b76?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Pieter van der Westhuizen says:

    Hi There,

    OutlookApp is a property that is automatically added to the AddinModule class when creating an Outlook Add-in using Add-in Express.

    It looks like the following:

    public Outlook._Application OutlookApp
    {
    get
    {
    return (HostApplication as Outlook._Application);
    }
    }

    Hope this helps!

  • https://secure.gravatar.com/avatar/8fe9449cade7b11cd48d1d080e7870bf?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G SharePoint Developer says:

    Thanks for the reply Pieter

  • https://secure.gravatar.com/avatar/73db6270d3d73575a87d2e757bb454df?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Sergio says:

    It doesnt work in a server, works locally but when you publish that not work in a server… what its the best way to do that?

  • https://secure.gravatar.com/avatar/e1a4c2b21a5186e0b27c1c601f418b76?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Pieter van der Westhuizen says:

    Hi Sergio,

    I’m afraid, I’m not sure what you mean. The code in this article is for a managed Outlook Add-in. It will be deployed using either clickonce or an msi installer on the users’ local machine.

  • https://secure.gravatar.com/avatar/bd67db2a22b8ae1ff4a26de6289deaec?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Beginner says:

    Hi, I am trying to schedule meeting and send to myself through QTP, please help

  • https://secure.gravatar.com/avatar/e1a4c2b21a5186e0b27c1c601f418b76?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Pieter van der Westhuizen says:

    Hi there,

    If by QTP you mean Quick Test Pro, then as far as I remember with QTP you can write VBA code.
    Try using the sample code as provided on this page in your VBA, you should be able to create and send Outlook appointments.

    You would need to reference the Microsoft Outlook Library in your VBA project for this to work.

  • https://secure.gravatar.com/avatar/11d8d1d1fafd75faef7bc1ffefe49046?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Andre says:

    Hi

    I wrote a VB code in Developer as my company that searches all the boardrooms we have and returns all the available boardrooms in a listbox by using the getfreebusy function. It was too difficult to distribute the function so I rather want to create an add-in using c# for outlook to do the same but I don’t know how to code it.

    Can you maybe help

  • https://secure.gravatar.com/avatar/e1a4c2b21a5186e0b27c1c601f418b76?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Pieter van der Westhuizen says:

    Hi Andre,

    It looks like you’re located in my neck of the woods. I’ve sent you an email. Maybe I can help you out.

  • https://secure.gravatar.com/avatar/f3e09cf2cf24ec98a7c7d7a2e727814e?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Edwin says:

    Hi,

    I was wondering if you can solve my question. Can this work fine on a Web application, I mean, like a Intranet site?. I saw above that someone posted that this don’t work in a server

    Hope you can understand what I mean.

  • https://secure.gravatar.com/avatar/ab4ec2858cfdf1e44dadf8c50fae314d?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Dmitry Kostochko (Add-in Express Team) says:

    Hi Edwin,

    This article and its code are purposed for desktop Outlook versions only.

  • https://secure.gravatar.com/avatar/36b64298fa94220369c5fdff44473022?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Imran says:

    Hi,

    Please help me as I want to develop web application in .net for Online meeting room book, pls find below as per my need.

    1. user entered all details as like mail id, subject, start dt, end dt, date, body etc..
    2. when user send meeting request, recipient receive mail notification and block outlook calendar for meeting request.
    3. same mail request send to recipient if booked user cancelled meeting.
    pls suggest me asap.

  • https://secure.gravatar.com/avatar/29957f26ad2d8ba527fd9cc8cfa7b2e0?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Andrei Smolin (Add-in Express Team) says:

    Hello Imran,

    Web applications are out of scope here. We discuss Office add-ins, not web applications. Specifically, the article above is devoted to Outlook add-ins.

  • https://secure.gravatar.com/avatar/8210ebb665d890f9a97a3534e517aa2b?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Jaya Rayasam says:

    Hello,

    Is there a way I can schedule an online meeting or Skype Meeting in the outlook instead of normal meeting ?

  • https://secure.gravatar.com/avatar/29957f26ad2d8ba527fd9cc8cfa7b2e0?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Andrei Smolin (Add-in Express Team) says:

    Hello Jaya,

    The Outlook object model doesn’t provide such a way.

  • https://secure.gravatar.com/avatar/cae41f579dfc4b03067c2c6bf9c811cd?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G hammad says:

    great article

  • https://secure.gravatar.com/avatar/fed408410d21c660d416f2878964ef85?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Hazie says:

    What if the location is an office room? assuming the room has an email address.

Post a comment

Have any questions? Ask us right now!