unit tdEmail;
interface
uses
Classes, SysUtils;
function SendEMail(
const AHost,AUser,APass, AToAdress,ASubject:
String;
const ABody,AAttachment: TStrings): Integer;
implementation
uses
IdMessage, IdSMTP, idAttachmentFile;
function SendEMail(
const AHost,AUser,APass, AToAdress,ASubject:
String;
const ABody,AAttachment: TStrings): Integer;
var
HMsg: TIdMessage;
HSMTP: TIdSMTP;
I: Integer;
begin
Result := 0;
{ Ok }
HSMTP := TIdSMTP.Create(
nil);
HSMTP.Host := AHost;
HSMTP.Username := AUser;
HSMTP.Password := APass;
HSMTP.Port := 25;
HSMTP.AuthType := atDefault;
HSMTP.Connect;
{ Message füllen }
HMsg := TIdMessage.Create(
nil);
HMsg.From.Address := AUser;
HMsg.Recipients.EMailAddresses := AToAdress;
HMsg.Subject := ASubject;
HMsg.Body.Clear;
HMsg.Body.Assign(ABody);
HMsg.Date := Now;
{ Anhang }
if Assigned(AAttachment)
then
begin
for I := 0
to AAttachment.Count - 1
do
TIdAttachmentFile.Create(HMsg.MessageParts,AAttachment[I]);
end;
try
try
HSMTP.Send(HMsg);
except
Result := HSMTP.LastCmdResult.NumericCode;
end;
finally
{ frei geben }
HMsg.Free;
HSMTP.Free;
end;
end;
end.