Mega Code Archive

 
Categories / Delphi / Examples
 

Sending an email from delphi with outlook

Outlook can be easily controlled through OLE. Try the sample procedure SendOutlookMail() from below. This does not work with Outlook Express - you can find more information on Outlook OLE automation at http://www.djpate.freeserve.co.uk/AutoOutl.htm. program MailWithOutlook; procedure SendOutlookMail; const olMailItem = 0; var Outlook: OleVariant; vMailItem: variant; begin try Outlook := GetActiveOleObject('Outlook.Application'); except Outlook := CreateOleObject('Outlook.Application'); end; vMailItem := Outlook.CreateItem(olMailItem); vMailItem.Recipients.Add('dummy@hotmail.com'); vMailItem.Subject := 'test email'; vMailItem.Body := 'This is a test'; vMailItem.Attachments.Add('C:\temp\sample.txt'); vMailItem.Send; VarClear(Outlook); end; begin end.