DelphiFAQ Home Search:

Sending an email from Delphi with Outlook

 

comments9 comments. Current rating: 4 stars (4 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
2017-07-12, 23:09:46
Christal from Monterrey, Mexico  
rating
I see your page needs some fresh articles.
Writing manually takes a lot of time, but there is tool
for this time consuming task, type in google: murgrabia's
tools unlimited content
2017-07-18, 09:12:09
Jonas from Brazil  
rating
I must say you have very interesting content
here. Your content should go viral. You need
initial boost only. How to get massive traffic? Search for:
Murgrabia's tools go viral
2017-11-17, 02:53:02
Dorothy from Brazil  
rating
I see you don't monetize your page, don't waste your traffic,
you can earn extra bucks every month because you've
got hi quality content. If you want to know how to make extra $$$, search for:
Boorfe's tips best adsense alternative

 

 

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: