1. Home
  2. Computing & Technology
  3. Delphi Programming

Send an email (with attachment) from Outlook

By Zarko Gajic, About.com

The following code can be used to send an Outlook e-mail message from Delphi:

~~~~~~~~~~~~~~~~~~~~~~~~~
const olMailItem = 0;
var Outlook: OLEVariant;
     MailItem: Variant;
begin
  try
   Outlook:=GetActiveOleObject('Outlook.Application') ;
  except
   Outlook:=CreateOleObject('Outlook.Application') ;
  end;
  MailItem := Outlook.CreateItem(olMailItem) ;
  with MailItem do begin
   Recipients.Add('delphi.guide@about.com') ;
   Subject := 'Subject: Outlook Mail From Delphi';
   Body := 'Welcome to my homepage:
http://delphi.about.com';
   Attachments.Add('C:\Windows\Win.ini') ;
   Send;
  end; {with}
   Outlook := Unassigned;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Controling sound volume from code
« How to "HotTrack" any control

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2000 Delphi Tips
  7. Send an email (with attachment) from Outlook

©2009 About.com, a part of The New York Times Company.

All rights reserved.