Implement mail option in program


I need to send a file :
 to a remote computer
 to a computer on a LAN
 by e-mail to an adress
 by internet (if possible) to a remote computer.

I know there are ways to do it. But which is the BEST? (The problem is that i'm not very familiar with networks) Is Ftp the best way? But then the program won't work on a standalone computer. Are there other ways? What do you need to declare (net adress, ...)
About e-mail, internet : haven't done this yet. How thus this works?
Uses it some mail programs like eudora, netscape or internet explorer? Or is it stand alone?

Are there easy components on the market (minimum of configuration)? Freeware if possible?

Please, help me to introduce me further in this net thing. Any help is welcome.

Who is Participating?
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.

I can't understand why ftp won't work on standalone PC. If this PC have no acces to internet or other network than you can't send data to them.

I think so mayby you need dial (or not if PC is connected) to Internet and then send data to other PC. When the other PC in not connected to the network you must send data to other which can resend this data after the other PC will connect.

If this is what you need than you must probably use MAIL, but then both clients need have own account. You can write serwer of course, however I think so you looking for other solution.

Probably the easiest and most "generic" way to do this would be to use the MAPI (Messaging Application Programming Interface). It's a standard part of windows and you can use it to "Attach" your file and e-mail it wherever you want. An application I wrote at work will email a file pretty much anywhere it's told, depending on the address it's going to. You shouldn't need any third-party components to handle this either :)

Check out the MAPI.HLP file included with Delphi 2.0 and above : )

Good luck with your project!

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
ZifNabAuthor Commented:
About stand alone PC, your right, my problem isn't good explained : let me try saying it another way.

1. The program i've made collects every day data (not much)
2. This data has to be sended somewhere. (e.g. to one other centrum, to a directory)
3. The program has to work on different systems
      a) stand alone computer with modem
      b) computer on a LAN
      c) computer with/without e-mail
4. Every centra wants his way of sending data :
      a) some with modem
      b) some with e-mail
      c) some with stand alone modem program
      d) ...
5. The program has to work on Win3.x, 95/NT
    -> I already made one in 95/NT and Win3.x
6. The program had already these options
      a) sending to a directory
      b) sending to a server by UUCP and UUCICO
      c) only prepare files with UUCP
          (for Win3.x, because UUCICO has to be called outside
           program. Why? I don't know)
7. Sending has to be as easy as pushing one button and
   the choosen send option will be used.
8. I have to use UUCP and UUCICO because of our LAN.
   Only calls to the server modems are alowed.
9. Well, I want to make all these sending possibilities,
   but, aren't there some sending functions which combine
   some of them ?
   e.g. Sending to a directory on the computer itself
        or ftp to an remote computer.
        --> Can ftp also send to a directory of the computer
            itself. (Windows 3.x,95/NT)
10. I know this sounds very strange, but I don't want to make
    my program endless long only for put in all the different
    sending possibilities, with there own error handling etc.
11. Hope I did'nt make you more confused.
12. Please, if you see a better way. SAY IT! Because I can't
    find another one.

Pegasus :

 Can give a small example? That's easier & quicker for understanding.

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Not sure it's a *small* example, but here's what *I* use! Let me know if I can be of further assistance : )

* * * * *

unit Mapi;


uses Classes, WinTypes, WinProcs, SysUtils, Dialogs;

  lpMapiFileDesc = ^TMapiFileDesc;
  TMapiFileDesc = Record
    ulReserved : LongInt;
    flFlags : LongInt;
    nPosition : LongInt;
    lpszPathName : PChar;
    lpszFileName : PChar;
    lpFileType : Pointer;

  lpMapiRecipDesc = ^TMapiRecipDesc;
  TMapiRecipDesc = Record
    ulReserved : LongInt;
    ulRecipClass : LongInt;
    lpszName : PChar;
    lpszAddress : PChar;
    ulEIDSize : LongInt;
    lpEntryID : Pointer;

  lpMapiMessage = ^TMapiMessage;
  TMapiMessage = Record
    ulReserved : LongInt;
    lpszSubject : PChar;
    lpszNoteText : PChar;
    lpszMessageType : PChar;
    lpszDateReceived : PChar;
    lpszConversationID : PChar;
    flFlags : LongInt;
    lpOriginator : lpMapiRecipDesc;
    nRecipCount : LongInt;
    lpRecips : lpMapiRecipDesc;
    nFileCount : LongInt;
    lpFiles : lpMapiFileDesc;

    szString = Array[0..255] of Char;

  MAPI_ORIG                     =  0;
  MAPI_TO                       =  1;
  MAPI_CC                       =  2;
  MAPI_BCC                      =  3;

  MAPI_LOGON_UI          :LongInt = $0001;
  MAPI_NEW_SESSION       :LongInt = $0002;
  MAPI_DIALOG            :LongInt = $0008;

    hSession : LongInt;
    EMSubject : String;
    EMText : String;
    EMRecip : Array[0..64] of szString;
    nRecips : LongInt;
    EMFiles : Array[0..64] of szString;
    nFiles : LongInt;

    function SendMessage: Integer;
    procedure InitializeMessage;
    procedure AddRecip(name : String);
    procedure AddAttachment(pathname : String);


{ Declare call to MAPI.DLL }

Function MAPISendMail(lhSession : LongInt;
                      ulUIParam : LongInt;
                      lpMessage : lpMapiMessage;
                      flFlags : LongInt;
                      ulReserved : LongInt) : LongInt; far;
                              external 'MAPI';

procedure InitializeMessage;
   i : Integer;
     EMSubject := '';
     EMText := '';
     for i := 0 to 64 do begin
     nRecips := 0;
     nFiles := 0;

procedure AddRecip(name : String);

procedure AddAttachment(pathname : String);

function SendMessage: Integer;
  MMsg       : TMapiMessage;
  Recip      : Array[0..64] of TMapiRecipDesc;
  Attachment : Array[0..64] of TMapiFileDesc;
  szSubject     : szString;
  szText        : szString;
  i : Integer;
  mFlags : LongInt;
  mFlags := MAPI_LOGON_UI;
  FillChar(MMsg,   Sizeof(TMapiMessage),   0);
  FillChar(Recip, Sizeof(TMapiRecipDesc)*64, 0);
  FillChar(Attachment,  Sizeof(TMapiFileDesc)*64,  0);
  MMsg.lpszSubject := StrPCopy(szSubject, EMSubject);
  MMsg.lpszNoteText := StrPCopy(szText, EMText);

  If nRecips > 0 then begin
     for i := 0 to nRecips - 1 do begin
        Recip[i].ulRecipClass := MAPI_TO;
        Recip[i].lpszName     := @EMRecip[i];
     MMsg.nRecipCount    := nRecips;
     MMsg.lpRecips       := @Recip;
     mFlags := mFlags + MAPI_DIALOG;

  If nFiles > 0 then
     for i := 0 to nFiles -1 do begin
     Attachment[i].nPosition    := $ffffffff;
     Attachment[i].lpszPathName := @EMFiles[i];
     MMsg.nFileCount    := nFiles;
     MMsg.lpFiles       := @Attachment;

  Result := MAPISendMail(hSession, 0, @MMsg, mFlags, 0);

ZifNabAuthor Commented:
10x 4 the *small* example!

I'm going to try it as soon as possible. (Today or Tomorrow)
As I can read, MAPI is only available in D2 and above (correct?). Is there also a way for D1 (Because I made my win3.x version in D1, the only way to make 16bit application,I believe)?
Do you have to distribute MAPI.DLL to every computer you install the program? Or is it default of windows?



To tell you the truth, I'm not sure if the MAPI.DLL is on EVERY windows install (although I show it in my Windows\system directory :^)

MAPI has kinda been around forever. I first used the MAPI functions in a Gupta SQLWindows application that was written under Windows 3.1 so I'd say that Delphi 1.0 will gladly use it (SQLWindows pre-dated Delphi by about 4 years I believe)

In general, when I need portability and am not really sure what messaging system (Lan, internet, etc) that the end-user will have, I implement the MAPI functions and let the operating system take care of the actual transport. All your application is worried about is composing a message and attaching a file, let the operating system deal with how it actually gets there :)

Good luck with your project and keep us informed on how it works out :)
ZifNabAuthor Commented:
So, with the MAPI function (e.g. your example) the computer itself searches a way to send the file?

-> That sounds very interesting!!

I'll keep you informed about the progress of the program.

Pegasus: Aren't you the author of a library with components, shipped on a CD? (e.g. Pegasus wheel,...)?
Zif, MAPI "knows" what messaging options the user has installed on the machine, be it a 3rd party mail program, Microsoft Exchange, or any other MAPI-compliant mail system (99.9% are!)

Authoring components distributed on a CD? Hhmmm Interesting Question! ;^)
ZifNabAuthor Commented:
Great, I get a solution and what problem do I get now?

... yeah, I haven't got MAPI(32).DLL ...

How do I get it? Is it free are do you have to pay for it?
If Eudora doesn't needs it, how can I send mail if a computer
has installed Eudora on it but not MAPI?

It's my understanding that MAPI(32).DLL is an intergral part of windows. It may not have been installed because none of the Standard Windows programs such as MS Exchange, Internet mail, etc were installed, so it left it out.

Go to Start | Settings | Control Panel | Add remove programs | Windows Setup and add  Microsft Messaging | Microsoft Mail Services and see if that installs the correct .DLL

It's part of Windows so you shouldn't have to pay for it.

Eudora, while being MAPI-Compliant, does not REQUIRE MAPI*.DLL to function. If it's there, then it will use it's services when needed, otherwise it doesn't care :)

Good luck!
ZifNabAuthor Commented:
Hi Pegasus!

Well, I finally made it working! Your sample code works very well, but I founded a component on the net which is easy to manipulate. I use TEMail2 component. It works just fine! Like your unit. I didn't know that you also could fax with MAPI, well that's also possible.
I found out that if you activate Mapi capabilities in Eudora, you don't have to have MS Exchange installed on your computer. So your solution about MAPI is really great! It works on every system with a mailing program!! THANKS FOR letting me know about MAPI!

And thanks for your sample, even I don't use it now, I learned a lot of it!

Thanks and see you!

Glad to help ZifNab!

MAPI is pretty flexible (as you've no doubt already know). Sometimes it is useful for programs to "talk" to each other (inter-process communication) but a little kludgy for that purpose. Another neato usage is to email system alerts or reports to certain users when things are not quite up to snuff within a program (SQL Server uses it to notify of low disk space, server faults, etc). It's so generic you can do just about anything with it. Enjoy & glad to help!

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.