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
|
procedure SendEmail(aTo : string;ASubject : string; ABody : string; AFileName : String);
var
Attachment : TIdAttachmentFile;
IdMessage : TIdMessage;
IdSMTP : TIdSMTP;
begin
IdSMTP := TIdSMTP.Create(nil);
IdMessage := TIdMessage.Create(nil);
Attachment := TIdAttachmentFile.Create(IdMessage.MessageParts,AFileName);
try
IdSMTP.Host := 'servermail';
IdSMTP.Port := 25;
IdSMTP.ConnectTimeout := 100;
try
IdMessage.Clear;
IdMessage.From.Address := 'mon@email.com';
IdMessage.Recipients.EMailAddresses := aTo;
IdMessage.Encoding := meMIME;
IdMessage.ContentType := 'multipart/mixed';
IdMessage.ContentTransferEncoding := 'base64';
IdMessage.Charset := idCharsetNames[idcsISO_8859_1];
IdMessage.Subject := ASubject;
IdMessage.Body.Text := ABody+#10#13#10#13;
try
if FileExists(AFileName) then
Attachment.DisplayName := ExtractFileName(AFileName);
IdSMTP.Connect;
IdSMTP.Send(IdMessage);
finally
IdSMTP.Disconnect();
end;
except on E : Exception do
Debug('SendEmail error :'+E.Message);
end;
finally
IdSMTP.Free;
IdMessage.Free;
end;
end; |
Partager