Solved

Implement mail option in program

Posted on 1997-11-05
12
203 Views
Last Modified: 2010-05-18
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.
 
0
Comment
Question by:ZifNab
  • 6
  • 5
12 Comments
 
LVL 3

Expert Comment

by:mirek071497
ID: 1349544
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.
0
 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 100 total points
ID: 1349545
Zifnab,

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!
Pegasus
0
 
LVL 8

Author Comment

by:ZifNab
ID: 1349546
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;
 
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1349547
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.
0
 
LVL 8

Author Comment

by:ZifNab
ID: 1349548
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;

0
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1349549
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
0
 
LVL 8

Author Comment

by:ZifNab
ID: 1349550
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,...)?
0
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1349551
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! ;^)
0
 
LVL 8

Author Comment

by:ZifNab
ID: 1349552
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?



0
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1349553
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
0
 
LVL 8

Author Comment

by:ZifNab
ID: 1349554
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;
0
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1349555
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
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question