ylwbrmis (Normal User)
Newbie
Messaggi: 14
Iscritto: 29/04/2009
|
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);
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
|
ylwbrmis (Normal User)
Newbie
Messaggi: 14
Iscritto: 29/04/2009
|
ciao anna,
si, ho risolto, se mi dici cosa ti serve, te lo faccio avere.
(per inciso, erano due i problemi)
1: la libreria openssl
2: isp che utilizzavo (vodafone, che non ha bene l'idea di cosa sia un server di posta)
saluti
Ultima modifica effettuata da ylwbrmis il 31/12/2009 alle 12:39 |