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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
var msg : String;
langue: String;
ZROQ : TZReadOnlyQuery;
fichierjoint : String;
begin
Screen.Cursor:=crHourGlass;
idSmtp1.Host:=smtpHost.Text;
idSmtp1.Username:=smtpUser.text;
idSmtp1.Password:=SmtpPassword.text;
idsmtp1.Port:=StrToInt(smtpPort.Text);
if useTLS.Checked then
begin
idSMTP1.UseTLS:=utUseImplicitTLS; // 1
idSMTP1.IOHandler:=IdSSLIOHandlerSocketOpenSSL1;
end
else begin
idSMTP1.UseTLS:=utNoTLSSupport; // 0
end;
//// Envoi Smtp
if PageControl1.ActivePageIndex>1 then langue:=Pagecontrol1.Pages[PageControl1.ActivePageIndex].Caption
else langue:=Pagecontrol1.Pages[2].Caption;
IdMessage1.Clear; //Efface l'entête et le corps du message
IdMessage1.From.Text :=smtpmail.text; //Adresse email de l'expediteur
IdMessage1.ReplyTo.EMailAddresses:=replyto.Text; //Adresse email où le destinataire pourra répondre
IdMessage1.Recipients.EMailAddresses:=smtpmail.Text; //Adresse email du destinataire
if UpperCase(Trim(smtpmail.Text))<>Uppercase(Trim(replyto.Text)) then
IdMessage1.Recipients.EMailAddresses:=IdMessage1.Recipients.EMailAddresses+';'+replyto.Text;
IdMessage1.Date:=Now; //Date de l'envoi du message
idMessage1.ContentType := 'multipart/mixed';
ZROQ:=TZReadOnlyQuery.Create(nil);
try
ZROQ.Connection:=ConnexionTest;
ZROQ.SQL.Clear;
ZROQ.SQL.Add('SELECT COALESCE(r.TITRE,''<Non traduit>''||');
ZROQ.SQL.Add('(SELECT TITRE FROM EMAIL_REFAB WHERE CODE_LANGUE=''FR'')) AS TITRE ,');
ZROQ.SQL.Add('COALESCE(r.CORPS,''<Non traduit>''||ASCII_CHAR(10)||');
ZROQ.SQL.Add('(SELECT COALESCE(CORPS,'''') FROM EMAIL_REFAB WHERE CODE_LANGUE=''FR'')) AS CORPS');
ZROQ.SQL.Add('FROM EMAIL_REFAB r WHERE CODE_LANGUE=:C');
ZROQ.ParamByName('C').AsString:=langue;
ZROQ.Active:=True;
IdMessage1.Subject:=Format(ZROQ.FieldByName('TITRE').AsString,['TEST ENVOI']); ; //Sujet du message
idmessage1.Body.Text:=ZROQ.FieldByName('CORPS').AsString;
ZROQ.Active:=False;
finally
ZROQ.Free;
end;
fichierjoint:=IncludeTrailingPathDelimiter(Adir.Directory)+'test.pdf';
with datamodule1 do
begin
RvRenderPDF1.Active := TRUE ;
RvSystem1.DefaultDest := rdFile;
RvSystem1.DoNativeOutput := false;
RvSystem1.RenderObject := RvRenderPDF1;
RvSystem1.OutputFileName := FichierJoint;
RvSystem1.SystemSetups := RvSystem1.SystemSetups - [ssAllowSetup];
RvRenderPDF1.DocInfo.Title:='Test pdf';
RvProject1.Open;
RvProject1.ExecuteReport('Test');
RvProject1.Close;
end;
with TIdAttachmentFile.Create(IdMessage1.MessageParts, fichierJoint)
do begin
ContentType := 'application/pdf';
FileName := 'test.pdf';
end;
try
idSMTP1.Connect;
idSMTP1.Send(idMessage1);
idSMTP1.Disconnect;
msg:=format('SMTP Ok, le message a été envoyé aux adresses suivantes %s et %s',[smtpmail.text,replyto.Text]);
MessageBox(0, Pchar(msg), 'Confirmation', MB_ICONINFORMATION or MB_OK);
except
on e : Exception do
begin
Screen.Cursor:=crdefault;
msg:='Impossible de se connecter au serveur SMTP'+sLineBreak+e.Message;
MessageBox(0,Pchar(msg), 'Erreur', MB_ICONERROR or MB_OK);
end;
end;
try deleteFile(fichierjoint); except end;
Screen.Cursor:=crdefault; |