Author: Tomas Rutkauskas
Sending an email from Delphi with Outlook
Answer:
Outlook can be easily controlled through OLE. Try the sample procedure
SendOutlookMail() from below.
This does not work with Outlook Express.
1 program MailWithOutlook;
2 3 procedure SendOutlookMail;
4 const5 olMailItem = 0;
6 var7 Outlook: OleVariant;
8 vMailItem: variant;
9 begin10 try11 Outlook := GetActiveOleObject('Outlook.Application');
12 except13 Outlook := CreateOleObject('Outlook.Application');
14 end;
15 vMailItem := Outlook.CreateItem(olMailItem);
16 vMailItem.Recipients.Add('dummy@hotmail.com');
17 vMailItem.Subject := 'test email';
18 vMailItem.Body := 'This is a test';
19 vMailItem.Attachments.Add('C:\temp\sample.txt');
20 vMailItem.Send;
21 22 VarClear(Outlook);
23 end;
24 25 end.