Add an Outlook calender item with code

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class ThisAddIn
{


 public Outlook.Inspectors PublicOutlookInspectors;
 private void ThisAddIn_Startup(object sender, System.EventArgs e)
 {
  NewOutlookAppointmentUsingCreateItem();
 }

 private void NewOutlookAppointmentUsingCreateItem()
 {
  Outlook.Application OutlookApplication = new Outlook.Application[];
  Outlook.AppointmentItem OutlookAppointmentItem = OutlookApplication.CreateItem(Outlook.OlItemType.olAppointmentItem);
  if (OutlookAppointmentItem != null) {
   OutlookAppointmentItem.Recipients.Add("User.Name@Sample.Com");
   OutlookAppointmentItem.Body = "Test Outlook appointment generated by code.";
   OutlookAppointmentItem.Subject = "Test Outlook appointment generated by code.";
   OutlookAppointmentItem.Location = "Test Outlook appointment generated by code.";
   OutlookAppointmentItem.Start = Now.AddHours(1);
   OutlookAppointmentItem.End = Now.AddHours(2);
   OutlookAppointmentItem.Importance = Outlook.OlImportance.olImportanceNormal;
   OutlookAppointmentItem.RequiredAttendees = OutlookAppointmentItem.Organizer;
   OutlookAppointmentItem.Display(true);
   try {
    OutlookAppointmentItem.Save();
    Runtime.InteropServices.Marshal.ReleaseComObject(OutlookAppointmentItem);
   } catch {
   }
  }
 }
 public ThisAddIn()
 {
  Startup += ThisAddIn_Startup;
 }

}

No comments:

Post a Comment