DelphiFAQ Home Search:
General :: Programming :: Delphi :: Network
Network (local network and Internet) programming under Windows with Delphi.


This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Compose an HTML email with Outlook from Delphi


I need to send an HTML formatted email with Outlook.


Take a look at the procedure below. Only in the newer versions of Outlook (98, 2000 and newer) you can send HTML-formatted emails. This works by assigning the HTML as a string to the MailItem's HTMLBody property instead of the Body property. Outlook 97 doesn't support this.

If you use Delphi 5, you should place an OutlookApplication component on your form. Then you can use early binding which is safer and faster. Instead of using type variant you could be using types like MAPIFolder, MailItem etc.

The example below uses no type library.
The advantage is that you are more likely to get it compiled right away.
The disadvantage is that you are less likely to get it working right away.

   Windows, ComObj, ActiveX;
   olMailItem = 0;
   Outlook, NmSpace, Folder: OleVariant; 
   miMail: Variant;
   Outlook := CreateOleObject('Outlook.Application');   
   miMail := Outlook.CreateItem(olMailItem);
   miMail.Subject := 'Hello Bill';
   // use this to send a plain text email (all versions of Outlook)
   miMail.Body := 'Attached is the list of email addresses.';
   // alternatively send an HTML email (not in Outlook 97)
   miMail.HTMLBody := '<font color=red>Attached is the <b>list of email</b> addresses.</font>';
   miMail.Attachments.Add('C:\temp\list.txt', EmptyParam, EmptyParam, EmptyParam);
You don't like the formatting? Check out SourceCoder then!
Generated 12:01:08 on May 25, 2020