Logo New book: Delphi 2007 Handbook
My blog in online
Delphi tech support service: support.marcocantu.com
Google
  Web www.marcocantu.com

Menu for Development

Site Menu
Delphi 2007 Handbook
Mastering Borland Delphi 2005
Essential Pascal
Essential Delphi
Buy Books Online
Code Repository
Newsgroups
White Papers
Tools
Conferences
Training
Delphi Links
Contact Marco

My Other Sites
Italian Site (www.marcocantu.it)
Developers Newsgroups Browser (dev.newswhat.com)
My town (www.piazzacavalli.net)
the delphi search
Wintech Italia (my company)

Breaking News
Buy Mastering Borland Delphi 2005 from Amazon
Free ebook: Mastering Delphi Update for Delphi 2006

Advertising
Home My Blog Books My Bookstore Development Links 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