Link to home
Start Free TrialLog in
Avatar of ZifNab
ZifNab

asked on

Implement mail option in program

Hi,

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.

Regards.
 
Avatar of mirek071497
mirek071497

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.
ASKER CERTIFIED SOLUTION
Avatar of Pegasus100397
Pegasus100397

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ZifNab

ASKER

Mirek,
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.

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

* * * * *

unit Mapi;

interface

uses Classes, WinTypes, WinProcs, SysUtils, Dialogs;

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

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

type
  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;
  end;

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

Const
  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;

var
    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);

Implementation

{ Declare call to MAPI.DLL }

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

procedure InitializeMessage;
var
   i : Integer;
begin
     EMSubject := '';
     EMText := '';
     for i := 0 to 64 do begin
         fillchar(EMRecip[i],255,0);
         fillchar(EMFiles[i],255,0);
     end;
     nRecips := 0;
     nFiles := 0;
end;

procedure AddRecip(name : String);
begin
     StrPCopy(@EMRecip[nRecips],name);
     inc(nRecips);
end;

procedure AddAttachment(pathname : String);
begin
     StrPCopy(EMFiles[nFiles],pathname);
     inc(nFiles);
end;

function SendMessage: Integer;
var
  MMsg       : TMapiMessage;
  Recip      : Array[0..64] of TMapiRecipDesc;
  Attachment : Array[0..64] of TMapiFileDesc;
  szSubject     : szString;
  szText        : szString;
  i : Integer;
  mFlags : LongInt;
begin
  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];
     end;
     MMsg.nRecipCount    := nRecips;
     MMsg.lpRecips       := @Recip;
     end
  else
     mFlags := mFlags + MAPI_DIALOG;

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

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

end.
Avatar of ZifNab

ASKER

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?

Regards,
ZifNab;

Well...

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 :)
Pegasus
Avatar of ZifNab

ASKER

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! ;^)
Avatar of ZifNab

ASKER

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!
Pegasus
Avatar of ZifNab

ASKER

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!

Regards,
ZifNab;
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!

Pegasus