Using IdSMTP in a dll

Giganews Newsgroups
Subject: Using IdSMTP in a dll
Posted by:  Captain Kirk (abu…@127.0.0.1)
Date: Sun, 7 Mar 2004

I've just coded this as a dll, somewhat quickly, I'm a little concerned
about the nils in TIdMessage.Create(nil); etc. I don't think they're
correct. What should I be putting in order to ensure that the dll works?

library SMTP;
{
This utility will send an email
}
uses
  SysUtils,
  Classes,
  IdSMTP,
  IdTCPConnection,
  IdTCPClient,
  IdMessageClient,
  IdPOP3,
  IdGlobal,
  IdMessage;

{$R *.res}
var SMTPServerName, SMTPUserName, SMTPUserEmail : ShortString;
IdSMTP1 : TIdSMTP;
IdMessage1 : TIdMessage;

procedure SMTPAssignData(SMTPServerName2, SMTPUserName2, SMTPUserEmail2 :
ShortString);
begin
SMTPServerName := SMTPServerName2;
SMTPUserName := SMTPUserName2;
SMTPUserEmail := SMTPUserEmail2;
end;

function SMTPConnect:Boolean;
begin
Result := False;
IdSMTP1 := TIdSMTP.Create(nil);
IdSMTP1.Host := SMTPServerName;
IdSMTP1.Connect(30000);
if IdSMTP1.Connected then Result := True;
end;

procedure SMTPDisconnect;
begin
IdSMTP1.Disconnect;
IdSMTP1.Free;
end;

procedure SMTPCreateNewMail;
begin
IdMessage1 := TIdMessage.Create(nil);
end;

procedure SMTPFreeMail;
begin
IdMessage1.Free;
end;

procedure SMTPAddTextLine(MText : ShortString);
begin
IdMessage1.Body.Add(MText);
end;

Function SMTPSendMail(ToAddress : ShortString):Boolean;
begin
IdMessage1.Date := Date;
IdMessage1.Sender.Address := SMTPUserEmail;
IdMessage1.Sender.Name := SMTPUserName;
IdMessage1.Recipients.EMailAddresses := ToAddress;
IdSMTP1.Send(IdMessage1);
end;

exports
SMTPAssignData,
SMTPDisconnect,
SMTPCreateNewMail,
SMTPFreeMail,
SMTPAddTextLine,
SMTPSendMai;
end.

--
Yours,

Rhys

Replies