Sending Mail Attachments in Delphi

I know this is a big question.

I would like to know how to send a mail message with a MAPI encoded attachment in Delphi.
Please do not direct me to third party controls that are not free and available on the internet.
I need to send it in Microsoft Exchange format.

I know the scope of the question which is why I have put so many points out.

I few pointers might be all I need to do this.
The attached document will be in Word95 format, not that it should be significant.

my email address is should you wish to mail me.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The following code sends a message and attachment from Fred to John.  (Add mapi to the uses clause.)

  Originator, Recipient: TMapiRecipDesc;
  FileAttachment: TMapiFileDesc;
  MapiMsg: TMapiMessage;
  if (MapiLogOn(0, nil, nil, MAPI_LOGON_UI or MAPI_NEW_SESSION , 0, @hMapi) = SUCCESS_SUCCESS) then
      FillChar(MapiMsg, SizeOf(TMapiMessage), 0);

      MapiMsg.lpszSubject := 'Test Message';
      MapiMsg.lpszNoteText := ' Hello.  This is the message text.  The End.';
      MapiMsg.flFlags := MAPI_RECEIPT_REQUESTED;

      FillChar(Originator, SizeOf(TMapiRecipDesc), 0);
      Originator.lpszName := 'Fred';
      Originator.lpszAddress := '';
      Originator.ulRecipClass := MAPI_ORIG;
      MapiMsg.lpOriginator := @Originator;

      MapiMsg.nRecipCount := 1;
      FillChar(Recipient, SizeOf(TMapiRecipDesc), 0);
      Recipient.lpszName := 'John';
      Recipient.lpszAddress := '';
      Recipient.ulRecipClass := MAPI_TO;
      MapiMsg.lpRecips := @Recipient;

      MapiMsg.nFileCount := 1;
      FillChar(FileAttachment, SizeOf(TMapiFileDesc), 0);
      FileAttachment.flFlags := 0;
      FileAttachment.lpszPathName := 'C:\autoexec.bat';
      FileAttachment.lpszFileName := 'autoexec.bat';
      MapiMsg.lpFiles := @FileAttachment;

      MapiSendMail(hMapi, 0, MapiMsg, MAPI_LOGON_UI, 0);

      MapiLogOff(hMapi, 0, 0, 0);


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This is freeware, easy, everything is possible, lot's of documenation, with source, for ALL delphi versions, for EVERY platform and good. But JimBob's answer is also correct.

Look at :

It's really recommended just to have a look at it.

Have fun,
c.u. ZifNab;
cmainAuthor Commented:
Thanks David.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.