How to use the NMSMTP component ?

I'd like to know how the NMSMTP component (from the FastNet tab in Delphi 5) is used. I want to use it to notify users automatically when their submitted forms are processed by the secretary personnel. The request from the users are sent via a distributed application, the processing is to be done in my application, working together with a MSSQL 7 database.
LVL 1
DonBartholomewAsked:
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.

intheCommented:
Hi
there is example in the delphi\demos\internet\smtp dirctory of your delphi installation.this example shows pretty much everything(parameter wise) that can be done with the component.
Regards Barry
0
intheCommented:
this next example was posted in another thread a couple o days ago:
To send mail add the following code:

BEGIN
  IF NOT(SMTP.Connected)
  THEN
  BEGIN
    SMTP.Host:= '192.130.0.1';
    SMTP.UserID := 'TheNeil';
    SMTP.Connect;
  END;

  IF SMTP.Connected
  THEN
  BEGIN
    SMTP.ClearParams := TRUE;
    SMTP.SubType := mtPlain;
    SMTP.EncodeType := uuMime;

    SMTP.PostMessage.FromAddress := 'TheNeil@geeza.com';
SMTP.PostMessage.FromName := 'The Neil';
    SMTP.PostMessage.ToAddress.Text := 'bloke@geeza.com';
    SMTP.PostMessage.Body.Text := 'Message';SMTP.PostMessage.Subject := 'Subject';
SMTP.PostMessage.Date := DateToStr(Date);
SMTP.SendMail;
MessageDlg('Mail sent', mtInformation, [mbOk], 0);
 END
  ELSE
 MessageDlg('NOT connected', mtInformation, [mbOk], 0);
END;

This example will send a simple message to the ToAddress address
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
intheCommented:
one more thing you probably alreadty know is it can be used with the the nmpop3 component (pop to read mail ,smtp to send) ..there is example of all the internet comps in the demos dir.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

TheNeilCommented:
God knwos what you're talking about with MSSQL and all that but I can help you out with the NMSMTP stuff. The following code simply constructs an NMSMTP component dynamically, connects to the server, builds the mail (using the supplied message) and sends it.

PROCEDURE SendMail(sMSG : STRING);
VAR
  SMTP : TNMSMTP;
BEGIN
  SMTP := TNMSMTP.Create(nil);
  TRY
    IF NOT(SMTP.Connected)     //We SHOULDN'T be connected but check anyway
    THEN
    BEGIN
      SMTP.Host:= '192.168.0.1';  //Setup the details of the SENDING account
      SMTP.UserID := 'neils';
      SMTP.Connect;
    END;

    IF SMTP.Connected             //By now we SHOULD be connected but check
    THEN
    BEGIN
      SMTP.ClearParams := TRUE;   //Setup the required fields
      SMTP.SubType := mtPlain;
      SMTP.EncodeType := uuMime;

      //The header details MUST be complete so we can stick in some dummy values
      SMTP.PostMessage.FromAddress := 'neils@minorplanet.com';
      SMTP.PostMessage.FromName := 'MyProg';

SMTP.PostMessage.ToAddress.Text := 'neils@minorplanet.com';
      SMTP.PostMessage.Body.Text := sMSG;

      SMTP.PostMessage.Subject := 'Test Mail';
      SMTP.PostMessage.Date := DateToStr(Date);

      SMTP.SendMail;   //Actually send the mail
    END;

    IF SMTP.Connected  //Tidy up
    THEN
      SMTP.Disconnect;
  FINALLY
    SMTP.Free;
  END;
END;

All you need to make sure of is that the host and user ID values are correct, and that the header is completed (it'll fail if it isn't). It's then just a case of passing in the subject text, body text, and destination details. If you're sending a lot of emails it would be worth doing the initialisation and connection just once, and keeping the connection open until you've finished.

The Neil
0
TheNeilCommented:
The suggested answer happens to be mine. Award the points how you see fit

The Neil
0
intheCommented:
like i said there is example in the delphi\demos\internet\smtp directory
i just thought a small peice of code would give the general idea and happened to have the other question opn also...


0
TheNeilCommented:
Sure, no problem - that's what the whole site is about

The Neil
0
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
Delphi

From novice to tech pro — start learning today.