Over a million developers have joined DZone.

Delphi: Send An Email With An Attachment Using OLE

·
In Delphi, this allows you to launch a new outlook window with an attachment. This will not work with Outlook Express.

This code was modified from the version seen here
More info here


uses ComObj //Delphi 5 or later
procedure TfrmHUD1_1.EmailDoc( path : String );
const
	olMailItem = 0;
var
	Outlook: OLEVariant;
	MailItem: Variant;
begin
  try
	Outlook:=GetActiveOleObject('Outlook.Application') ;
  except
	Outlook:=CreateOleObject('Outlook.Application') ;
  end;
	MailItem := Outlook.CreateItem(olMailItem) ;
	MailItem.Recipients.Add('johndoe@hotmail.com') ;
	MailItem.Subject := 'Subject: Outlook Mail From Delphi';
	MailItem.Body := 'Body of the email';
	MailItem.Attachments.Add(path) ;
	MailItem.Display; //MailItem.Send to skip the window and just send the email
	VarClear(Outlook);
end;
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}