Oppure

Loading
29/04/09 12:07
ylwbrmis
Secondo me non ne vengo a capo.
Ho questa Dll, che utilizzo per postare email, ho aggiunto l'autenticazione per la posta certificata ( uso aruba) non capisco dove sbaglio.

library DllEmail;

uses
SysUtils,
Classes,
IdSSLOpenSSL,
IdBaseComponent,
IdComponent,
IdTCPConnection,
IdTCPClient,
IdExplicitTLSClientServerBase,
IdMessage,
IdMessageClient,
IdAttachmentFile,
IdSMTPBase,
IdSMTP,
IdIOHandler,
IdIOHandlerSocket,
IdIOHandlerStack,
IdSSL,
IdSASLAnonymous,
IdSASL,
IdSASLUserPass,
IdSASL_CRAM_MD5,
IdSASLLogin,
IdUserPassProvider;

{$R *.res}

function DllConnettiSmtp(SmtpServer: string; ilmessaggio: TidMessage;
Pec, Loginutente, PwdUtente: string;
Porta: Integer): Boolean;
var
IdSMTP: TIdSMTP;
IdSSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL;
IdUserPassProvider: TIdUserPassProvider;
IdSASLLogin: TIdSASLCramMd5;
begin
try
IdSMTP := TIdSMTP.Create(nil);
IdSMTP.Host := SmtpServer;
IdSMTP.Port := 25;
IdSMTP.UseTLS:= utNoTLSSupport;
if (Porta > 0) then
IdSMTP.Port := Porta;
if (Pec = 'N') then
IdSMTP.AuthType:= atDefault
else
begin
IdSMTP.UseTLS:= utUseExplicitTLS;
IdSMTP.ManagedIOHandler := True;
IdSMTP.AuthType:= atSASL;
IdSSLIOHandlerSocketOpenSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdSMTP);
IdSSLIOHandlerSocketOpenSSL.Destination := SmtpServer + ':' +
inttostr(Porta);
IdSMTP.IOHandler := IdSSLIOHandlerSocketOpenSSL;
IdUserPassProvider := TIdUserPassProvider.Create;
IdUserPassProvider.Username:= Loginutente;
IdUserPassProvider.Password:= PwdUtente;
IdSASLLogin := TIdSASLCramMd5.Create;
IdSASLLogin.UserPassProvider := IdUserPassProvider;
IdSMTP.SASLMechanisms.Add.SASL := IdSASLLogin;
end;
IdSMTP.UseEhlo := True;
with IdSMTP do
begin
try
ConnectTimeout := 5000;
Connect;
if (PEC = 'S') then
begin
if not Authenticate then
begin
result := False;
exit;
end;
end;
if Assigned(ilmessaggio) then
Send(ilmessaggio);
Result := Connected;
finally
if Connected then
Disconnect;
end;
end;
finally
if Assigned(IdSASLLogin) then
freeandnil(IdSASLLogin);
if Assigned(IdUserPassProvider) then
freeandnil(IdUserPassProvider);
if Assigned(IdSSLIOHandlerSocketOpenSSL) then
freeandnil(IdSSLIOHandlerSocketOpenSSL);
if Assigned(IdSMTP) then
freeandnil(IdSMTP);
end;
end;

function DllSpedisciMail(FromEmail, ToEmail, SmtpServer, Subj, TextEmail: string;
Attach_files: TStringList;
Pec, Loginutente, PwdUtente: String;
Porta: Integer): boolean; stdcall;
var
ilmessaggio: TIdMessage;
i: integer;
begin
try
ilmessaggio := TIdMessage.create(nil);
ilmessaggio.ReceiptRecipient.Address := FromEmail;
ilmessaggio.ReplyTo.EMailAddresses := FromEmail;
ilmessaggio.From.Text := FromEmail;
ilmessaggio.Recipients.Add.Text := ToEmail;
ilmessaggio.Subject := Subj;
ilmessaggio.Body.Text := TextEmail;
for i := 0 to Attach_files.Count - 1 do
TIdAttachmentFile.Create(ilmessaggio.MessageParts,Attach_files.Strings[i]);
Result := DllConnettiSmtp(SmtpServer,ilmessaggio,Pec,Loginutente,PwdUtente,
Porta);
finally
ilmessaggio.Free;
end;
end;

function DllSpedisciMailFattura(FromEmail, ToEmail, SmtpServer, Subj,
TextEmail, Allegato, Pec, Loginutente,
PwdUtente: string; Porta: Integer): boolean; stdcall;
var
ilmessaggio: TIdMessage;
begin
try
ilmessaggio := TIdMessage.Create(nil);
ilmessaggio.ReceiptRecipient.Address := FromEmail;
ilmessaggio.ReplyTo.EMailAddresses := FromEmail;
ilmessaggio.From.Text := FromEmail;
ilmessaggio.Recipients.Add.Text := ToEmail;
ilmessaggio.Subject := Subj;
ilmessaggio.Body.Text := TextEmail;
if (Allegato > '') then
TIdAttachmentFile.Create(ilmessaggio.MessageParts,Allegato);
Result := DllConnettiSmtp(SmtpServer,ilmessaggio,Pec,Loginutente,PwdUtente,
Porta);
finally
ilmessaggio.Free;
end;
end;

exports DllSpedisciMailFattura,
DllSpedisciMail;
begin
end.

saluti
aaa
29/04/09 13:58
pierotofy
E quando richiami la funzione che errore viene fuori?
Il mio blog: piero.dev
29/04/09 18:23
ylwbrmis
Postato originariamente da pierotofy:

E quando richiami la funzione che errore viene fuori?

al "connect" si blocca non da errori e il trhead viene continuamente rilanciato.
aaa
29/04/09 20:40
pierotofy
Non riesco a capire... che intendi per "il thread viene automaticamente rilanciato"?
Il mio blog: piero.dev
30/04/09 6:16
ylwbrmis
try
ConnectTimeout := 5000;
Connect; >>>>>>>>>>>>>
al connect si pianta, nessun errore.
Visto con il debug, vedo che nel EventLog di delphi 2005 lancia un trhead, credo siano le librerie di SSL, che viene lanciato e dopo 5 secondi va in exit e poi riprende di nuovo
assegnando sempre un nuovo ID restando sempre fermo nel connect.
Oggi faro delle modifiche per vedere che risposte mi da il server e poi vi faccio sapere.
saluti

aaa
30/04/09 6:19
ylwbrmis
try
ConnectTimeout := 5000;
Connect; >>>>>>>>>>>>>
al connect si pianta, nessun errore.
Visto con il debug, vedo che nel EventLog di delphi 2005 lancia un trhead, credo siano le librerie di SSL, che viene lanciato e dopo 5 secondi va in exit e poi riprende di nuovo
assegnando sempre un nuovo ID restando sempre fermo nel connect.
Oggi faro delle modifiche per vedere che risposte mi da il server e poi vi faccio sapere.
saluti

aaa
30/04/09 21:52
pierotofy
Il codice sembra a posto... le uniche cose che mi vengono in mente sono:
1) Il server che non riesce a dialogare
2) Un bug del componente Indy (che non sarebbe nuovo, quando ho sviluppato il mio multiplayerpoker ho avuto problemi con i componenti Indy e ho risolto usando un altra libreria, se non ricordo male).
Il mio blog: piero.dev
30/12/09 1:35
apoppea
Ciao ylwbrmis mi chiamo anna, hai risolto il problema per inviare email certificata?
Avrei bisogno di un programma del genere, sono alle prime armi ed è molto difficile per me farne uno da sola.
ciauz
aaa