timeout problem

Giganews Newsgroups
Subject: timeout problem
Posted by:  Rhys Sage (abu…@127.0.0.1)
Date: Tue, 25 Nov 2003

I'm getting a problem with my SMTP - a timeout on connection - it never
connects. What's the problem?

unit smtp2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, IdMessage, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP;

type
  TForm1 = class(TForm)
    IdSMTP1: TIdSMTP;
    IdMessage1: TIdMessage;
    Memo1: TMemo;
    Label2: TLabel;
    Button1: TButton;
    LabeledEdit1: TLabeledEdit;
    LabeledEdit2: TLabeledEdit;
    LabeledEdit3: TLabeledEdit;
    LabeledEdit4: TLabeledEdit;
    LabeledEdit5: TLabeledEdit;
    LabeledEdit6: TLabeledEdit;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    CheckBox1: TCheckBox;
    Button5: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure IdSMTP1Connected(Sender: TObject);
    procedure IdSMTP1Disconnected(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var MyList : TStringList;
begin
MyList := TStringList.Create;
MyList.Add(LabeledEdit1.Text);
MyList.Add(LabeledEdit2.Text);
MyList.Add(LabeledEdit3.Text);
MyList.Add(LabeledEdit4.Text);
MyList.Add(LabeledEdit5.Text);
MyList.Add(LabeledEdit6.Text);
MyList.SaveToFile('settings.txt');
MyList.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
var MyList : TStringList;
begin
MyList := TStringList.Create;
MyList.LoadFromFile('settings.txt');
if MyList.Count <> 6 then exit;
LabeledEdit1.Text := MyList.Strings[0];
LabeledEdit2.Text := MyList.Strings[1];
LabeledEdit3.Text := MyList.Strings[2];
LabeledEdit4.Text := MyList.Strings[3];
LabeledEdit5.Text := MyList.Strings[4];
LabeledEdit6.Text := MyList.Strings[5];
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
idSMTP1.Username := LabeledEdit5.Text;
idSMTP1.Password := LabeledEdit6.Text;
idSMTP1.Host := LabeledEdit4.Text;
idSMTP1.Connect(10);
end;

procedure TForm1.IdSMTP1Connected(Sender: TObject);
begin
Caption := 'Server is now ready to send mail';
end;

procedure TForm1.IdSMTP1Disconnected(Sender: TObject);
begin
Caption := 'Server had hung up';
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
idSMTP1.Disconnect;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
// set message headers
idMessage1.From.Address := LabeledEdit1.Text;
idMessage1.Sender.Address := LabeledEdit1.Text;
idMessage1.Subject := LabeledEdit3.Text;
idMessage1.Organization := 'Some organisation';
idMessage1.Date := Date;
idMessage1.Recipients.EMailAddresses := LabeledEdit2.Text;
idMessage1.Body.AddStrings(Memo1.Lines);
idMessage1.ProcessHeaders;
idSMTP1.Send(idMessage1);
end;

Replies