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.UseDelphiToSendEmailFromMicrosoftOutlookDisplay(Sender: TObject);
var
OutlookApplication, OutlookMailItem: Variant;
begin
//be sure ComObj and Variants units are included in the "uses" clause

OutlookApplication := Null;
OutlookMailItem := 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 Mail Item
try
OutlookMailItem := OutlookApplication.CreateItem(0);
//reference
//https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem
except
OutlookMailItem := Null;
//add error/exception handling code as desired
end;

If VarIsNull(OutlookMailItem) = False then
begin
OutlookMailItem.To := 'recipient@example.com'; //change the recipient email address
OutlookMailItem.Subject := 'Sending email from Outlook programmatically - Display before sending';
OutlookMailItem.Body := 'This email is being sent from Outlook... Display before sending...';
OutlookMailItem.Display;
//reference
//https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem.display
end;
finally
OutlookMailItem := Unassigned;
OutlookApplication := Unassigned;
end;
end;
end;




Posted: Saturday, May 14, 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