DelphiFAQ Home Search:

Sending an email from Delphi with Outlook

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and 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

 

 

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.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

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:
photo Add a picture:

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.