Navigation Menu Search PhysiologyWeb
PhysiologyWeb Logo Search PhysiologyWeb
   
— share —
Share on Facebook    Share on X    Share on LinkedIn    Share on Pinterest    Share on Reddit    Email    Copy URL
procedure TForm1.UseDelphiToCreateOutlookAppointmentAndInviteAttendees(Sender: TObject);
var
OutlookApplication, OutlookAppointmentItem: Variant;
begin
//be sure ComObj and Variants units are included in the "uses" clause

OutlookApplication := Null;
OutlookAppointmentItem := Null;

try
//create Outlook OLE
OutlookApplication := CreateOleObject('Outlook.Application');
except
OutlookApplication := Null;
//add error/exception handling code as desired
end;

If VarIsNull(OutlookApplication) = False then
begin
try
//Create Outlook Appointment Item
try
OutlookAppointmentItem := OutlookApplication.CreateItem(1); //olAppointmentItem = $00000001
//reference
//https://docs.microsoft.com/en-us/office/vba/api/outlook.appointmentitem
except
OutlookAppointmentItem := Null;
//add error/exception handling code as desired
end;

If VarIsNull(OutlookAppointmentItem) = False then
begin
OutlookAppointmentItem.MeetingStatus := 1; //olMeeting = 1; set to 0 if there are no recipients/attendees
OutlookAppointmentItem.Subject := 'Outlook Meeting Item';
OutlookAppointmentItem.Body := 'This Microsoft Outlook calendar meeting was created programmatically by Delphi!' + DoubleLineBreak + 'Calendar meeting invitations were sent to required and optional attendees.';
OutlookAppointmentItem.Location := 'My office';
OutlookAppointmentItem.AllDayEvent := False;
OutlookAppointmentItem.Start := EncodeDateTime(2022, 8, 7, 10, 0, 0, 0);
OutlookAppointmentItem.End := EncodeDateTime(2022, 8, 7, 10, 50, 0, 0);
OutlookAppointmentItem.Recipients.Add('recipient1@example.com'); //change the recipient email address
OutlookAppointmentItem.Recipients.Add('recipient2@example.com'); //change the recipient email address
OutlookAppointmentItem.RequiredAttendees := 'recipient1@example.com'; //change the recipient email address
OutlookAppointmentItem.OptionalAttendees := 'recipient2@example.com'; //change the recipient email address
OutlookAppointmentItem.Save;
OutlookAppointmentItem.Send;
//reference
//https://docs.microsoft.com/en-us/office/vba/api/Outlook.MailItem.Send(method)
//https://docs.microsoft.com/en-us/office/vba/api/outlook.olmeetingstatus
end;
finally
OutlookAppointmentItem := Unassigned;
OutlookApplication := Unassigned;
end;
end;
end;




Posted: Saturday, August 6, 2022
Last updated: Tuesday, March 18, 2025
— share —
Share on Facebook    Share on X    Share on LinkedIn    Share on Pinterest    Share on Reddit    Email    Copy URL