procedure SendEmails;
var IdSMTP: TIdSMTP;
IdMsg: TIdMessage;
I : Integer;
begin
IdSMTP:=TIdSMTP.Create(nil);
IdSMTP.Host:='my.domain.nl'; // replace by your outgoing server
IdSMTP.Port:=25;
IdSMTP.Username := 'MyUserName';
IdSMTP.Password := 'MyPassword';
try
if NOT IdSMTP.Connected then
IdSMTP.Connect;
For I := 0 to Query1.Recordcount -1 do
begin
try
IdMsg:=TIdMessage.Create(nil);
IdMsg.From.Address:= edit1.Text;
IdMsg.Subject:= edit2.text;
IdMsg.Recipients.EMailAddresses:= Query1.FieldByName('Email').Text;
// Start some function to personalize body per customer
IdMsg.Body.Text := PersonalizeEmailForCustomer;
try
IdSMTP.Connect;
IdSMTP.Send(IdMsg);
except
Showmessage('Error when sending E-mail');
end;
finally
IdMsg.Free;
end;
Query1.Next;
end;
finally
if IdSMTP.Connected then
IdSMTP.Disconnect;
IdSMTP.Free;
end;
end;
|