I want to invoke oulook mail from my code in Delphi. It should be like if user select a menu option "Send Mail" , the new mail message window should appear . If outlook is not running aleady, it should start Outlook also. MS oulook 2003 and 2007 only.

Please help.

Tried the code but another issue. Its not compiling the lines

Any files need to be included? its says undefined.

Retrieves a reference to an IDispatch interface to a currently running, registered COM object.

Unit ComObj

Category COM utilities

Delphi syntax:

function GetActiveOleObject(const ClassName: string): IDispatch;

C++ syntax:

typedef System::DelphiInterface< IDispatch > _di_IDispatch;
extern PACKAGE _di_IDispatch __fastcall GetActiveOleObject(const AnsiString ClassName);


GetActiveOleObject returns a reference to the IDispatch interface of the active object for the given class indicated by ClassName. ClassName is the programmatic ID for the class of the active object from the OLE running object table. GetActiveOleObject is used to access the OLE running object table. To add an object to this table, use the RegisterActiveObject API.

If either the the class object or the IDispatch interface are not successfully returned, an EOleSysError exception is raised.

I am not able to compile the code. Eventhough its part of Delphi API. please help. Just tried an independent program which invokes Outlook mail.

I could invoke outlook with the follwing code section.

aMAPIObj := TMAPIMail.Create(nil);
aMAPIObj.Attachments := aAttachmentList;

using: TMAPIMail = class(TComponent)

this used Mapi.pas Delphi library.
I am able to attach a file which is created and saved on a harddisk location. But what I want is to send the attachment file (JPEG) directly to the outlook without saving into the harddisk. Can anbody help me out in sending as an OLE in the message body or as the attachment? the API require the path of the attachment file .

A ShellExecute command (in ShellApi module) can make it:

ShellExecute(0, 'open', PChar(S), nil, nil, SW_SHOW);

S is a string variable containing 'mailto:' as leading characters. This command will open a new-mail window of the default mail processor no matter whether the processor is running.