1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
uses
...
IdMessage, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdMessageClient, IdSMTP
....
procedure EnvoyerMailIndy(serveurSmtp,adresseSource,adresseDestination,sujet,text:string;noport:integer;User,Pwd:string;filename:string='');overload;
Var
IdSMTP1: TIdSMTP;
IdMessage1: TIdMessage;
i:integer;
idText2: TidText;
Attach:TIdAttachment;
Begin
IdMessage1:=TIdMessage.Create(nil);
IdSMTP1:=TIdSMTP.Create(nil);
Attach:=nil;
idText2 := TidText.Create(idMessage1.MessageParts);
idText2.ContentType := 'text/plain';
idText2.Body.Text := text;
With IdMessage1 do
Begin
CharSet:='iso-8859-1';
Encoding:=meMIME;
ContentType:= 'multipart/mixed';
From.Text:=adresseSource;
Recipients.EMailAddresses:=adresseDestination;
Subject:=sujet;
if filename<>'' then begin
TIdAttachment.Create(IdMessage1.MessageParts,filename);
end;
End;
IdSMTP1.Host:=serveurSmtp;
IdSMTP1.Port:=noport;
IdSMTP1.Username:=User;
IdSMTP1.Password:=Pwd;
IdSMTP1.Connect(1000);
try
IdSMTP1.send(IdMessage1);
finally
{ Et on pense a se déconnecter }
IdSMTP1.Disconnect;
End;
{ et a libérer les objets créés }
if Assigned(attach) and (attach<>nil) then Attach.Free;
IdMessage1.Free;
IdSMTP1.Free;
End; |
Partager