Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to Create Birthday Reminders Using Microsoft Outlook, in C#

0.00/5 (No votes)
4 Jan 2004 3  
This article shows you hot to use Microsoft Outlook appointments. I used a version of the code to put reminders in for my family members.

Introduction

I guess it isn't rocket science to put birthday reminders into Outlook, but nevertheless, doing it in C# code cost me more effort than it should have. So without further ado, here is the code.

Steps

  1. Ensure you reference Microsoft Outlook, then create a new application.
    Outlook._Application olApp = 
       (Outlook._Application) new Outlook.Application();
  2. Log on. (I think email needs to be running)
    Outlook.NameSpace mapiNS = olApp.GetNamespace("MAPI")
    string profile = "";
    mapiNS.Logon(profile, null, null, null);
  3. Repeat the line.
    CreateYearlyAppointment(olApp, "Birthday", 
       "Kim", new DateTime(2004, 03,08, 7, 0, 0));

    for your wife and kids etc. etc.!!!

The Code

static void CreateYearlyAppointment(Outlook._Application olApp, 
    string reminderComment, string person, DateTime dt)
  {
   // Use the Outlook application object to create an appointment

   Outlook._AppointmentItem apt = (Outlook._AppointmentItem)
    olApp.CreateItem(Outlook.OlItemType.olAppointmentItem);
  
   // set some properties

   apt.Subject = person + " : " + reminderComment;
   apt.Body = reminderComment;
  
   apt.Start = dt;
   apt.End   = dt.AddHours(1);
 
   apt.ReminderMinutesBeforeStart = 24*60*7 * 1;  // One week reminder

   
   // Makes it appear bold in the calendar - which I like!

   apt.BusyStatus = Outlook.OlBusyStatus.olTentative; 
   
   apt.AllDayEvent = false;
   apt.Location = "";
   
   Outlook.RecurrencePattern myPattern = apt.GetRecurrencePattern();
   myPattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursYearly;
   myPattern.Interval = 1;
   apt.Save();
  }

Reap The Rewards

With a one week reminder, you will never again forget your Mum's birthday.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here