Click here to Skip to main content
15,880,392 members
Articles / Programming Languages / C#
Article

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

Rate me:
Please Sign up or sign in to vote.
4.00/5 (11 votes)
4 Jan 2004CPOL 116.7K   41   24
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.
    C#
    Outlook._Application olApp = 
       (Outlook._Application) new Outlook.Application();
  2. Log on. (I think email needs to be running)
    C#
    Outlook.NameSpace mapiNS = olApp.GetNamespace("MAPI")
    string profile = "";
    mapiNS.Logon(profile, null, null, null);
  3. Repeat the line.
    C#
    CreateYearlyAppointment(olApp, "Birthday", 
       "Kim", new DateTime(2004, 03,08, 7, 0, 0));

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

The Code

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Australia Australia
Frank has been in computing since the age of the dinosaurs. He prefers playing table tennis to writing C#, C++, VB, or any of the other dozen or more languages he has written since the Jurasic.

Comments and Discussions

 
GeneralError when creating birthday reminder in ASP.NET Pin
c-mor23-Mar-09 3:30
c-mor23-Mar-09 3:30 
GeneralRe: Error when creating birthday reminder in ASP.NET Pin
Tauiqr17-Oct-12 22:03
Tauiqr17-Oct-12 22:03 
QuestionAdding the reminder in a Calendar in Public Folder?? Pin
Rahul Vac26-Mar-07 23:27
Rahul Vac26-Mar-07 23:27 
QuestionRegarding to creating Birthday Reminder Pin
Thimani12-Feb-07 18:27
Thimani12-Feb-07 18:27 
GeneralSolution if you get error 80004005 Pin
KirbzStar28-Nov-06 14:56
KirbzStar28-Nov-06 14:56 
GeneralLogon without Outlook Running Pin
mtbbiker3-Oct-05 1:35
mtbbiker3-Oct-05 1:35 
Questionversion independent ? Pin
fracalifa31-Mar-05 23:50
fracalifa31-Mar-05 23:50 
GeneralError Outlook unrecoqnized Pin
chikku8-Mar-04 22:28
chikku8-Mar-04 22:28 
GeneralRe: Error Outlook unrecoqnized Pin
partyganger8-Mar-04 23:56
partyganger8-Mar-04 23:56 
GeneralRe: Error Outlook unrecoqnized Pin
NITH30-Apr-04 3:35
NITH30-Apr-04 3:35 
GeneralError Outlook unrecoqnized Pin
chikku8-Mar-04 22:27
chikku8-Mar-04 22:27 
QuestionAnyone ported this to C#? Pin
dragomir3-Feb-04 0:02
dragomir3-Feb-04 0:02 
AnswerRe: Anyone ported this to C#? Pin
NITH30-Apr-04 3:27
NITH30-Apr-04 3:27 
QuestionCreate a message rule? Pin
dragomir22-Jan-04 22:33
dragomir22-Jan-04 22:33 
Hi,
Excellent article!
Do you know how I can add a new rule to Outlook Express programatically?
AnswerRe: Create a message rule? Pin
Frank Eden26-Jan-04 11:50
Frank Eden26-Jan-04 11:50 
GeneralSending Outlook items Pin
Anonymous13-Jan-04 1:30
Anonymous13-Jan-04 1:30 
GeneralRe: Sending Outlook items Pin
Frank Eden13-Jan-04 10:59
Frank Eden13-Jan-04 10:59 
GeneralExcellent article Pin
Per Søderlind5-Jan-04 21:30
sussPer Søderlind5-Jan-04 21:30 
GeneralRe: Excellent article Pin
NITH30-Apr-04 3:29
NITH30-Apr-04 3:29 
GeneralWhats the purpose Pin
super5-Jan-04 18:29
professionalsuper5-Jan-04 18:29 
GeneralRe: Whats the purpose Pin
Frank Eden5-Jan-04 18:54
Frank Eden5-Jan-04 18:54 
GeneralRe: Whats the purpose Pin
gUnOm20-Feb-05 22:49
gUnOm20-Feb-05 22:49 
GeneralRe: Whats the purpose Pin
Malik Nasir14-May-06 22:55
Malik Nasir14-May-06 22:55 
GeneralRe: Whats the purpose Pin
laribum4-Sep-06 2:44
laribum4-Sep-06 2:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.