public void AddAppointment(Appointment apt) { try { Outlook.Application outlookApp = new Outlook.Application(); // creates new outlook app Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem); // creates a new appointment oAppointment.Subject = apt.Subject; oAppointment.Body = apt.Body; oAppointment.Location = apt.Location; oAppointment.Start = Convert.ToDateTime(apt.StartTime); oAppointment.End = Convert.ToDateTime(apt.EndTime); oAppointment.ReminderSet = true; oAppointment.ReminderMinutesBeforeStart = apt.ReminderMinutesBeforeStart; oAppointment.Importance = Outlook.OlImportance.olImportanceHigh; oAppointment.BusyStatus = Outlook.OlBusyStatus.olBusy; oAppointment.RequiredAttendees = apt.RequiredAttendees; oAppointment.Save(); Outlook.MailItem mailItem = oAppointment.ForwardAsVcal(); // email address to send to mailItem.To = apt.RequiredAttendees +";" + apt.Organizer; //" [email protected]"; // send mailItem.Send(); } catch (Exception ex) { Console.WriteLine(ex.Message + "\r\n" + ex.InnerException + "\r\n" + "\r\n"); } }
static void Main(string[] args) { Appointment apt = new Appointment(); apt.StartTime = DateTime.Now; apt.EndTime = DateTime.Now; apt.Organizer = "Josh"; apt.Body = "Sample Body"; apt.Duration = 2; apt.ReminderMinutesBeforeStart = 15; apt.RequiredAttendees = "*****@*****.**"; apt.Subject = "Test"; apt.Topic = "Testing the code"; OutlookHandle OLH = new OutlookHandle(); try { OLH.AddAppointment(apt); } catch (Exception ex) { } }