Mega Code Archive

 
Categories / Delphi / Activex OLE
 

How to send an email using ms-outlook

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,ComObj; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure SendOutlookMail; const olMailItem = 0; var Outlook: OleVariant; vMail: variant; begin try Outlook := GetActiveOleObject('Outlook.Application'); except Outlook := CreateOleObject('Outlook.Application'); end; vMail := Outlook.CreateItem(olMailItem); vMail.Recipients.Add('Test@Programmer.com'); vMail.Subject := 'DevSuperPage'; vMail.Body := 'This is a test'; vMail.Attachments.Add('C:\test.text'); vMail.Send; VarClear(Outlook); end; procedure TForm1.Button1Click(Sender: TObject); begin SendOutlookMail; end; end.