Marco's Web Center

Menu for Development

Site Menu
Object Pascal Handbook
Delphi Handbooks Collection
Mastering Borland Delphi 2005
(Old) White Papers
(Old)Tools
(Old) Conferences

My Other Sites
Italian Site (www.marcocantu.it)
the delphi search

Spirit of delphi

Advertising
Home My Blog Books Object Pascal Marco

Home: Code Repository: Mastering Delphi 5

Project WEBMAIL2

Project Structure


WEBMAIL2.DPR

program WebMail2;

{$APPTYPE CONSOLE}

uses
  WebBroker,
  CGIApp,
  WMailDm in 'WMailDm.pas' {WebModule1: TWebModule};

begin
  Application.Initialize;
  Application.CreateForm(TWebModule1, WebModule1);
  Application.Run;
end.

WMAILDM.PAS

unit WMailDm;

interface

uses
  Windows, Messages, SysUtils, Classes, HttpApp, Psock, NMsmtp;

type
  TWebModule1 = class(TWebModule)
    Mail: TNMSMTP;
    procedure WebModule1WebActionItem1Action(Sender: TObject;
      Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  WebModule1: TWebModule1;

implementation

{$R *.DFM}

procedure TWebModule1.WebModule1WebActionItem1Action(
  Sender: TObject; Request: TWebRequest;
  Response: TWebResponse; var Handled: Boolean);
var
  OutString: string;
begin
  OutString := Request.ContentFields.Values ['firstname'];
  OutString := OutString + ' ' +
    Request.ContentFields.Values ['lastname'];
  OutString := OutString + ' [' +
    Request.ContentFields.Values ['email'] + ']';

  // send email
  Mail.PostMessage.FromAddress := OutString;
  Mail.Connect;
  Mail.SendMail;
  Mail.Disconnect;

  Response.Content := Response.Content +
    '<HTML><HEAD><TITLE>Newsletter</TITLE></HEAD>' +
    '<BODY><H1>Newsletter</H1><H2>Subscription received</H2><hr>' +
    '<H4>You''re registered in our database as <br>' +
    OutString + '</h4>' +
    '</BODY></HTML>';
end;

end.

WMAILDM.DFM

object WebModule1: TWebModule1
  OldCreateOrder = True
  Actions = <
    item
      Default = True
      Name = 'WebActionItem1'
      OnAction = WebModule1WebActionItem1Action
    end>
  Left = 372
  Top = 190
  Height = 479
  Width = 741
  object Mail: TNMSMTP
    Host = 'AST'
    Port = 25
    ReportLevel = 0
    UserID = 'marco'
    PostMessage.ToAddress.Strings = (
      'marco@AST')
    PostMessage.Body.Strings = (
      'Subscription')
    PostMessage.Subject = 'Subscribe'
    EncodeType = uuMime
    ClearParams = True
    SubType = mtPlain
    Charset = 'us-ascii'
    Left = 32
    Top = 24
  end
  object NMSMTP1: TNMSMTP
    Port = 25
    ReportLevel = 0
    EncodeType = uuMime
    ClearParams = True
    SubType = mtPlain
    Charset = 'us-ascii'
    Left = 96
    Top = 40
  end
end