emin Posted February 17, 2021 Share Posted February 17, 2021 Hi I use below code to send an email. It works well on standalone mode, however on IIS does not send mails. I set SMTP email configuration on IIS server. The problem still exists Quote unit uepostagonder; interface uses System.SysUtils, dialogs, IdTCPConnection, IdExplicitTLSClientServerBase, IdMessageClient, IdSMTP, IdMessage, IdIOHandler, IdBaseComponent, IdComponent, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL; Type TEmail= Class (TObject) private ferror:boolean; fmes:string; fToEmailAdresse:string; fObject:string; fMessage:string; public Constructor Create(MyToEmailAdress, MyObject, MyMessage:string); // initialisation de l'Objet avec capture directe Destructor Destroy; overload; // j'utilise, par defaut celle de l'Ancêtre : TObject // procedure Init; comme ya a pas de controle Set, je peux Créer l'Objet avec Capture Directe function Send:boolean; published property erreur:boolean read ferror write ferror; property mes:string read fmes write fmes; property ToEmailAdress:string read fToEmailAdresse write fToEmailAdresse; property Objet:string read fObject write fObject; property CorpsMessage:string read fMessage write fMessage; End; implementation constructor TEmail.Create(MyToEmailAdress, MyObject, MyMessage:string); begin //1. Hériter de la Classe ancetre TObject // inherited; //2. initialiser Capture directe (ne passe pas par Set) fToEmailAdresse:=MyToEmailAdress; fObject:=MyObject; fMessage:=MyMessage; end; destructor TEmail.Destroy; begin //1. faire quelques choses //2. puis hériter de la Classe ancetre TObject inherited; end; function TEmail.Send: boolean; var IdSSLIOHandlerSocket: TIdSSLIOHandlerSocketOpenSSL; IdSMTP: TIdSMTP; IdMessage: TIdMessage; begin IdSSLIOHandlerSocket := TIdSSLIOHandlerSocketOpenSSL.Create(Nil); IdSMTP := TIdSMTP.Create(Nil); IdMessage := TIdMessage.Create(Nil); try IdSSLIOHandlerSocket.SSLOptions.Method := sslvSSLv23; IdSSLIOHandlerSocket.SSLOptions.Mode := sslmClient; IdSSLIOHandlerSocket.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2]; IdSMTP.IOHandler := IdSSLIOHandlerSocket; IdSMTP.UseTLS := utUseImplicitTLS; IdSMTP.AuthType := satDefault; // Using gmail Server (do not modify this) IdSMTP.Host := 'smtp.yandex.com.tr'; IdSMTP.Port := 465; // Change this : your gmail adress + password : //==================================== IdSMTP.Username :='xxx@xxx.com'; // (1) IdSMTP.Password :='xxxx'; // From IdMessage.From.Address :='xxx@xxx.com'; // the same in (1) IdMessage.From.Name := 'xxxxx'; //==================================== // To //==================================== IdMessage.Recipients.Add.Text := fToEmailAdresse; IdMessage.Subject := fObject; IdMessage.ContentTransferEncoding := '8bit'; IdMessage.ContentType := 'text/plain'; IdMessage.CharSet := 'UTF-8'; IdMessage.Body.Clear; IdMessage.Body.Text:=fMessage; //==================================== ferror:=False; fmes:='E-posta başarıyla gönderildi'; try IdSMTP.Connect; IdSMTP.Authenticate; except on E: Exception do begin ferror:=True; fmes:=E.Message; end; end; // Envoie du message if not ferror then begin try IdSMTP.Send(IdMessage); except On E: Exception do begin ferror:=True; fmes:=E.Message; end; end; end; finally IdSMTP.Disconnect; UnLoadOpenSSLLibrary; FreeAndNil(IdMessage); FreeAndNil(IdSSLIOHandlerSocket); FreeAndNil(IdSMTP); end; result:=not ferror; end; End. Link to comment Share on other sites More sharing options...
Abaksoft Posted February 18, 2021 Share Posted February 18, 2021 Hello Emin, i will try it on IIS and come back soon. (The code works fine as Service / Hyperserver). Link to comment Share on other sites More sharing options...
emin Posted February 18, 2021 Author Share Posted February 18, 2021 Thank you. I am looking forward Link to comment Share on other sites More sharing options...
Oliver Morsch Posted February 18, 2021 Share Posted February 18, 2021 Where are the openSSL dll's located? Link to comment Share on other sites More sharing options...
emin Posted February 18, 2021 Author Share Posted February 18, 2021 In the application.dll folder Link to comment Share on other sites More sharing options...
Oliver Morsch Posted February 18, 2021 Share Posted February 18, 2021 This does not Work. Try system32 or syswow64. 2 Link to comment Share on other sites More sharing options...
emin Posted February 18, 2021 Author Share Posted February 18, 2021 I really thank you this valuable information. Because I had searched web for long hours and found nothing. System32 didn't work. SysWOW64 is OK 2 Link to comment Share on other sites More sharing options...
Abaksoft Posted February 18, 2021 Share Posted February 18, 2021 Many Thx Oliver, Many Thx Emin, for this precious info. Best Regards Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now