DelphiFAQ Home Search:

Sending an email from Delphi with Outlook

 

comments6 comments. Current rating: 3 stars (1 votes). Leave comments and/ or rate it.

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.
You don't like the formatting? Check out SourceCoder then!

Comments:

2006-03-27, 10:49:33
anonymous from Brazil  
how to write OnSaveAs event handler? I need capture the full path of filename that user save to disk. thanks

atc, Luiz Gustavo.
lugbestrio@yahoo.com
2008-11-28, 08:44:22
kris@anti-crisis-software.com from Ukraine  
rating
The best way to contol Outlook from Delphi is AIRMail SDK ( http://anti-crisis-..sdk.html), Try it!
2010-01-01, 02:46:58
anonymous from Iran  
دمت گرم

2010-02-10, 09:56:00
anonymous from Kazakhstan  
Спасибо очень сильно помогло
2010-02-10, 09:57:45
anonymous from Kazakhstan  
Thank you very much
2010-04-04, 15:00:36
anonymous from Mexico  
How do I quit from outlook?
I tried with outlook.quit and does'nt work

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: