Jump to content

Forgot  password


ygerdel

Recommended Posts

 

 

Exactly, what I need is to validate the user's email in the database and send the password to that email, then the user must change the password immediately. Do you have an example to send emails with Uigui? I am using delphi tokyo 10.2.

Link to comment
Share on other sites

...send emails with Uigui? 

i use the indy components (included in delphi)

 

uses .....   IdMessage, IdBaseComponent,
  IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase,
  IdMessageClient, IdSMTPBase, IdSMTP, IdText, IdAttachmentFile, IdAttachment,
  uniMultiItem.....

 

procedure Tsystem_mail.create_mail;
var
                Msg: TIdMessage;
                Attachment: TIdAttachment;
                IdSMTP: TIdSMTP;
                TextPart: TIdText;
                my_mailtext:TStrings;
                HtmPart: TIdText;
                myEncoding : TEncoding;
begin

if ((UniMainModule.MAILKONTEN.FieldByName('BENUTZERNAME').AsString <> '') AND
   (UniMainModule.MAILKONTEN.FieldByName('SMTP').AsString <> '') AND
   (UniMainModule.MAILKONTEN.FieldByName('PORT_SMTP').AsString <> '') AND
   (UniMainModule.MAILKONTEN.FieldByName('KENNWORT').AsString <> '')) then
begin


try
                   IdSMTP := TIdSMTP.Create(nil);
                   idSMTP.Username :=UniMainModule.MAILKONTEN.FieldByName('BENUTZERNAME').AsString;
                   idSMTP.Password :=UniMainModule.MAILKONTEN.FieldByName('KENNWORT').AsString;
                   idSMTP.Host     :=UniMainModule.MAILKONTEN.FieldByName('SMTP').AsString;
                   idSMTP.Port     :=UniMainModule.MAILKONTEN.FieldByName('PORT_SMTP').AsInteger;

                   Msg := TIdMessage.Create(nil);
                   Msg.From.address :=UniMainModule.MAILKONTEN.FieldByName('ANTWORTADRESSE').AsString;;
                   Msg.Recipients.EMailAddresses := uniedit1.Text;
                   Msg.CCList.EMailAddresses     := uniedit4.Text;
                   Msg.BccList.EMailAddresses    := uniedit3.Text;
                   Msg.Subject:= uniedit2.Text;

                   Msg.ContentType := 'multipart/mixed; charset="utf-8"';
                   Msg.ClearBody;

                   UniMainModule.ANHANG.First;
                   if UniMainModule.ANHANG.recordcount > 0 then
                   begin
                       while not UniMainModule.ANHANG.Eof do
                       begin

                          if fileexists(UniMainModule.ANHANG.FieldByName('PFAD').AsString) then  TIdAttachmentFile.Create(Msg.MessageParts, UniMainModule.ANHANG.FieldByName('PFAD').AsString);

                          UniMainModule.ANHANG.next;
                       end;
                   end;

                   // Anhang löschen
                   UniMainModule.ANHANG.First;
                   while not UniMainModule.ANHANG.Eof do
                       begin
                           UniMainModule.ANHANG.Delete;
                           UniMainModule.ANHANG.First;
                       end;

                   


                   if UniHTMLMemo1.Lines.Text <> '' then
                   begin
                   HtmPart := TIdText.Create(Msg.MessageParts, nil );
                   HtmPart.ContentType := 'text/html; charset="utf-8"';
                   htmpart.Body:=UniHTMLMemo1.Lines;
                   end;


                    try
                        idSMTP.Connect();
                        idSMTP.Send(Msg);
                        mainform.nachricht('eMail send ...');
                    except on e:Exception do ShowMessage('Message Error -> '+e.message);
                    end;
              finally
                     if idSMTP.Connected then idSMTP.Disconnect();
                     IdSMTP.Free;
                     HtmPart.Free;
                     Msg.MessageParts.Clear;

                     Msg.Free;
              end;

end
else
begin
  mainform.nachricht('Mailkonto ist nicht vollständig konfiguriert');
end;



close;

end;

 

Link to comment
Share on other sites

On 2/5/2019 at 1:23 PM, d.bernaert said:

I use the following library to send mails from our platforms.

It features a mail service, so mails can be placed very fast in a waiting list so there is no delay waiting for the mails to be send, the service handles the rest automatically: https://www.emailarchitect.net/easendmail

Dominique

Great component, i also use it for years within Delphi/uniGui...sending bulk mail in combination

with the Mail Queue services :)

Link to comment
Share on other sites

Thank you so much everyone for your contributions. I implemented this code and works perfectly:

 

 

Do not forget to add the files  to the project's execution folder.

ssleay32.dll and libeay32.dll

......\Win32\Debug

Code:

uses
  MainModule, uniGUIApplication, UnDMSistemas, UnFuncGral, UnErrorGral,
  IdSMTP, IdSSLOpenSSL, IdMessage, IdText, IdAttachmentFile,
  IdExplicitTLSClientServerBase, BCrypt,
  UnLogin;

function UnFrmOlvidoPassword: TUnFrmOlvidoPassword;
begin
  Result := TUnFrmOlvidoPassword
    (UniMainModule.GetFormInstance(TUnFrmOlvidoPassword));
end;

procedure TUnFrmOlvidoPassword.UnBtnEnviarClick(Sender: TObject);

var
  IdSSLIOHandlerSocket: TIdSSLIOHandlerSocketOpenSSL;
  IdSMTP: TIdSMTP;
  IdMessage: TIdMessage;

  IdText: TIdText;

begin
  IdSSLIOHandlerSocket := TIdSSLIOHandlerSocketOpenSSL.Create(Self);
  IdSMTP := TIdSMTP.Create(Self);
  IdMessage := TIdMessage.Create(Self);

    begin
      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;
        IdSMTP.Host := 'smtp.gmail.com';
        IdSMTP.Port := 465;
        IdSMTP.Username := 'xxx@xxxxxx.com';
        IdSMTP.Password := 'xxxxxxx';

        IdMessage.From.Address := 'xxxxxxx@xxxxxxx.com';
        IdMessage.From.Name := 'xxxxxxxxxxxxx';
        IdMessage.Recipients.Add.Text := vVeriEMail;
        IdMessage.Subject := 'xxxxxxxxxxxxxxx';
        IdMessage.Encoding := meMIME;


        IdText := TIdText.Create(IdMessage1.MessageParts);
        IdText.Body.Add('Body');
        IdText.ContentType := 'text/plain; charset=iso-8859-1';

        try
          IdSMTP.Connect;
          IdSMTP.Authenticate;
        except
          on E: Exception do
          begin
            Showmessage('Error al autenticar la conexion: ' + E.Message);
            Exit;
          end;
        end;
        // Envio de  mensaje
        try
          IdSMTP.Send(IdMessage);

          end;
        except
          On E: Exception do
          begin
            Showmessage('Error al enviar mensaje: ' + E.Message);
          end;
        end;
      finally

        IdSMTP.Disconnect;

        UnLoadOpenSSLLibrary;

        FreeAndNil(IdMessage);
        FreeAndNil(IdSSLIOHandlerSocket);
        FreeAndNil(IdSMTP);
      end;
    end

end;

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...