unit MailThread;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Controls,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdMessageClient, IdSMTP, StdCtrls, IdIOHandler, IdIOHandlerSocket,
IdSSLOpenSSL, IdMessage, ComCtrls;
type
TMailThread =
class(TThread)
private
procedure MailProc(mail: TIdMessage; path:
String;
SMTP: TIdSmtp;globalcnt: Integer);
protected
procedure Execute();
override;
public
constructor Create (CreateSuspended: Boolean; mail: TIdMessage; path:
String;
SMTP: TIdSmtp;globalcnt: Integer);
overload;
end;
implementation
uses
atfiles;
var EMail: TIdMessage;
fPath:
String;
SMTP1: TIdSMTP;
cnt: Integer;
constructor TMailThread.Create (CreateSuspended : boolean ;mail: TIdMessage; path:
String;
SMTP: TIdSmtp;globalcnt: Integer) ;
begin
inherited Create (CreateSuspended) ;
{Email.Create(nil);}
{SMTP1.create(nil);}
Email:= TIdMessage.create(Form1);
Smtp1 := TIdSMTP.create(Form1);
EMail:= mail;
fPath:= path;
SMTP1:=
SMTP;
cnt:= globalcnt;
end ;
procedure TMailThread.Execute;
begin
MailProc(Email, fPath, SMTP1, cnt);
end;
procedure TMailThread.MailProc;
var i: Integer;
begin
for i := 1
to globalcnt -1
do
begin
if FileExists('
./temporary/'+ExtractFileName(path)+'
_'+Inttostr(i))
then
TIdAttachment.Create(mail.MessageParts, '
./temporary/'+ExtractFileName(path)+'
_'+Inttostr(i));
Mail.Subject := ExtractFileName(path)+'
_'+Inttostr(i);
smtp.Connect;
try
smtp.Send(mail);
smtp.Disconnect;
finally
Mail.MessageParts.Clear;
end;
end;
end;
end.