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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
intheConnect With a Mentor Commented:
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
 
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:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
All Courses

From novice to tech pro — start learning today.