Jump to content

Mehmet Emin

uniGUI Subscriber
  • Posts

    229
  • Joined

  • Last visited

  • Days Won

    6

Everything posted by Mehmet Emin

  1. Rica ederim. Ekli mail gönderimi haricinde, AttachHtmlFile foksiyonu da aşağıdaki şekilde kullanılabilir: HTML formatındaki içeriğe örneğin bir logo gömmek istersek. BodyStr := '<html><head></head>'+ '<body>'+ '<p><img src="cid:ticket.png"></p>'+ '</body>'+ '</html> AttachHtmlFile( 'ticket.png', '\xxxxxxxxxx\xxxxxxxxx\ticket.png', 'image/png', 'ticket.png'); //AContentID parametresi HTML kodu içerisinde cid:ticket.png olarak referans veriliyor. procedure TSSLEmail.AttachHtmlFile(const AName, AFileName, AContentType, AContentID: string; ATempFile: Boolean);
  2. Yukarıdaki kodun formatı bozuksa aşağıdaki adrese de yükledim: https://www.dropbox.com/s/kl77k2yk9pr36c5/SecureMailClient.zip?dl=1
  3. unit SecureMailClient; interface uses IdMessage, Classes, IdSMTP, IdText, IdAttachment, IdAttachmentFile, IdMessageParts, IdMessageBuilder, System.SysUtils, System.IOUtils, System.Contnrs; const SMTP_PORT_EXPLICIT_TLS = 587; type TSSLEmailAttachFile = class Name: string; FileName: string; ContentType: string; ContentID: string; TempFile: Boolean; HtmlRelated: Boolean; end; TSSLEmail = class(TObject) private IdMessage: TIdMessage; SMTP: TIdSMTP; FedDelaySeconds: Integer; FedHTMLBody: TStrings; FedBody: TStrings; FedSMTPPort: Integer; FedToEmail: string; FedSubject: string; FedSMTPServer: string; FedCCEmail: string; FedPassword: string; FedBCCEmail: string; FedSenderName: string; FedUserName: string; FedPriority: TIdMessagePriority; FedSenderEmail: string; FedSSLConnection: Boolean; FAttachFiles: TObjectList; // Getter / Setter procedure SetBody(const Value: TStrings); procedure SetHTMLBody(const Value: TStrings); procedure Init; procedure InitMailMessage; procedure InitSASL; procedure AddSSLHandler; public constructor Create; overload; constructor Create(const ASMTPServer: string; const ASMTPPort: Integer; const AUserName, APassword: string); overload; destructor Destroy; override; procedure SendEmail; procedure AttachHtmlFile(const AName, AFileName, AContentType, AContentID: string; ATempFile: Boolean = False); procedure AttachTempFile(const AName, AFileName, AContentType: string); procedure AttachFile(const AName, AFileName, AContentType: string); // Properties property edDelaySeconds: Integer read FedDelaySeconds write FedDelaySeconds; property edHTMLBody: TStrings read FedHTMLBody write SetHTMLBody; property edBCCEmail: string read FedBCCEmail write FedBCCEmail; property edBody: TStrings read FedBody write SetBody; property edCCEmail: string read FedCCEmail write FedCCEmail; property edPassword: string read FedPassword write FedPassword; property edPriority: TIdMessagePriority read FedPriority write FedPriority; property edSenderEmail: string read FedSenderEmail write FedSenderEmail; property edSenderName: string read FedSenderName write FedSenderName; property edSMTPServer: string read FedSMTPServer write FedSMTPServer; property edSMTPPort: Integer read FedSMTPPort write FedSMTPPort; property edSSLConnection: Boolean read FedSSLConnection write FedSSLConnection; property edToEmail: string read FedToEmail write FedToEmail; property edUserName: string read FedUserName write FedUserName; property edSubject: string read FedSubject write FedSubject; end; TEmailSenderThread = class(TThread) private FSSLEmail: TSSLEmail; protected procedure Execute; override; public constructor Create(CreateSuspended: Boolean); reintroduce; destructor Destroy; override; property SSLEmail: TSSLEmail read FSSLEmail; end; implementation uses IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase, IdBaseComponent, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdSASLLogin, IdSASL_CRAM_SHA1, IdSASL, IdSASLUserPass, IdSASL_CRAMBase, IdSASL_CRAM_MD5, IdSASLSKey, IdSASLPlain, IdSASLOTP, IdSASLExternal, IdSASLDigest, IdSASLAnonymous, IdUserPassProvider; constructor TSSLEmail.Create; begin inherited; Init; FedBody := TStringList.Create; FedHTMLBody := TStringList.Create; FAttachFiles := TObjectList.Create; end; procedure TSSLEmail.Init; begin edSSLConnection := True; edPriority := TIdMessagePriority.mpNormal; end; procedure TSSLEmail.AttachHtmlFile(const AName, AFileName, AContentType, AContentID: string; ATempFile: Boolean); var LAttachFile: TSSLEmailAttachFile; begin LAttachFile := TSSLEmailAttachFile.Create; with LAttachFile do begin Name := AName; FileName := AFileName; ContentType := AContentType; ContentID := AContentID; TempFile := ATempFile; HtmlRelated := True; end; FAttachFiles.Add(LAttachFile); end; procedure TSSLEmail.AttachTempFile(const AName, AFileName, AContentType: string); var LAttachFile: TSSLEmailAttachFile; begin LAttachFile := TSSLEmailAttachFile.Create; with LAttachFile do begin Name := AName; FileName := AFileName; ContentType := AContentType; ContentID := ''; TempFile := True; HtmlRelated := False; end; FAttachFiles.Add(LAttachFile); end; procedure TSSLEmail.AttachFile(const AName, AFileName, AContentType: string); var LAttachFile: TSSLEmailAttachFile; begin LAttachFile := TSSLEmailAttachFile.Create; with LAttachFile do begin Name := AName; FileName := AFileName; ContentType := AContentType; ContentID := ''; TempFile := False; HtmlRelated := False; end; FAttachFiles.Add(LAttachFile); end; constructor TSSLEmail.Create(const ASMTPServer: string; const ASMTPPort: Integer; const AUserName, APassword: string); begin Create; edSMTPServer := ASMTPServer; edSMTPPort := ASMTPPort; edUserName := AUserName; edPassword := APassword; end; destructor TSSLEmail.Destroy; begin FAttachFiles.Free; edHTMLBody.Free; edBody.Free; inherited; end; // Setter / Getter ----------------------------------------------------------- procedure TSSLEmail.SetBody(const Value: TStrings); begin FedBody.Assign(Value); end; procedure TSSLEmail.SetHTMLBody(const Value: TStrings); begin FedHTMLBody.Assign(Value); end; // Send the mail ------------------------------------------------------------- procedure TSSLEmail.SendEmail; var I: Integer; LAttachFile: TSSLEmailAttachFile; begin IdMessage := TIdMessage.Create; try InitMailMessage; SMTP := TIdSMTP.Create; try if edSSLConnection then begin AddSSLHandler; if edSMTPPort = SMTP_PORT_EXPLICIT_TLS then SMTP.UseTLS := utUseExplicitTLS else SMTP.UseTLS := utUseImplicitTLS; end; if (edUserName<>'') or (edPassword<>'') then begin SMTP.AuthType := satSASL; InitSASL; end else begin SMTP.AuthType := satNone; end; SMTP.Host := edSMTPServer; SMTP.Port := edSMTPPort; SMTP.ConnectTimeout := 30000; SMTP.UseEHLO := True; SMTP.Connect; try SMTP.Send(IdMessage); for I := 0 to FAttachFiles.Count -1 do begin LAttachFile := TSSLEmailAttachFile(FAttachFiles[I]); if LAttachFile.TempFile then begin if TFile.Exists(LAttachFile.FileName) then TFile.Delete(LAttachFile.FileName); end; end; finally SMTP.Disconnect; end; finally SMTP.Free; end; finally IdMessage.Free; end; end; // Prepare the mail ---------------------------------------------------------- procedure TSSLEmail.InitMailMessage; var I: Integer; FMessageBuilder: TIdMessageBuilderHtml; FAttachment: TIdMessageBuilderAttachment; LAttachFile: TSSLEmailAttachFile; begin FMessageBuilder := TIdMessageBuilderHtml.Create; try if edBody.Text <> '' then FMessageBuilder.PlainText.Text := edBody.Text; if edHTMLBody.Text <> '' then FMessageBuilder.Html.Text := edHTMLBody.Text; IdMessage.Sender.Text := edSenderEMail; IdMessage.From.Name := edSenderName; IdMessage.From.Address := edSenderEMail; IdMessage.ReplyTo.EMailAddresses := edSenderEmail; IdMessage.Recipients.EMailAddresses := edToEmail; IdMessage.Subject := edSubject; IdMessage.Priority := edPriority; IdMessage.CCList.EMailAddresses := edCCEMail; IdMessage.ReceiptRecipient.Text := ''; IdMessage.BccList.EMailAddresses := edBCCEMail; for I := 0 to FAttachFiles.Count -1 do begin LAttachFile := TSSLEmailAttachFile(FAttachFiles[I]); if LAttachFile.HtmlRelated then FAttachment := FMessageBuilder.HtmlFiles.Add(LAttachFile.FileName, LAttachFile.ContentID) else FAttachment := FMessageBuilder.Attachments.Add(LAttachFile.FileName, LAttachFile.ContentID); FAttachment.Name := LAttachFile.Name; FAttachment.ContentType := LAttachFile.ContentType; end; FMessageBuilder.FillMessage(IdMessage); for I := 0 to IdMessage.MessageParts.Count-1 do begin if IdMessage.MessageParts[I].PartType = mptAttachment then begin IdMessage.MessageParts[I].FileName := IdMessage.MessageParts[I].Name; IdMessage.MessageParts[I].ContentType := IdMessage.MessageParts[I].ContentType; IdMessage.MessageParts[I].ContentID := IdMessage.MessageParts[I].ContentID; end; end; IdMessage.CharSet := 'UTF8'; finally FMessageBuilder.Free; end; end; procedure TSSLEmail.AddSSLHandler; var SSLHandler: TIdSSLIOHandlerSocketOpenSSL; begin SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(SMTP); SSLHandler.SSLOptions.Method := sslvSSLv23; SSLHandler.SSLOptions.Mode := sslmClient; SSLHandler.SSLOptions.VerifyMode := []; SSLHandler.SSLOptions.VerifyDepth := 0; SMTP.IOHandler := SSLHandler; end; procedure TSSLEmail.InitSASL; var IdUserPassProvider: TIdUserPassProvider; IdSASLCRAMMD5: TIdSASLCRAMMD5; IdSASLCRAMSHA1: TIdSASLCRAMSHA1; IdSASLPlain: TIdSASLPlain; IdSASLLogin: TIdSASLLogin; IdSASLSKey: TIdSASLSKey; IdSASLOTP: TIdSASLOTP; IdSASLAnonymous: TIdSASLAnonymous; IdSASLExternal: TIdSASLExternal; begin IdUserPassProvider := TIdUserPassProvider.Create(SMTP); IdUserPassProvider.Username := edUserName; IdUserPassProvider.Password:= edPassword; IdSASLCRAMSHA1 := TIdSASLCRAMSHA1.Create(SMTP); IdSASLCRAMSHA1.UserPassProvider := IdUserPassProvider; IdSASLCRAMMD5 := TIdSASLCRAMMD5.Create(SMTP); IdSASLCRAMMD5.UserPassProvider := IdUserPassProvider; IdSASLSKey := TIdSASLSKey.Create(SMTP); IdSASLSKey.UserPassProvider := IdUserPassProvider; IdSASLOTP := TIdSASLOTP.Create(SMTP); IdSASLOTP.UserPassProvider := IdUserPassProvider; IdSASLAnonymous := TIdSASLAnonymous.Create(SMTP); IdSASLExternal := TIdSASLExternal.Create(SMTP); IdSASLLogin := TIdSASLLogin.Create(SMTP); IdSASLLogin.UserPassProvider := IdUserPassProvider; IdSASLPlain := TIdSASLPlain.Create(SMTP); IdSASLPlain.UserPassProvider := IdUserPassProvider; SMTP.SASLMechanisms.Add.SASL := IdSASLCRAMSHA1; SMTP.SASLMechanisms.Add.SASL := IdSASLCRAMMD5; SMTP.SASLMechanisms.Add.SASL := IdSASLSKey; SMTP.SASLMechanisms.Add.SASL := IdSASLOTP; SMTP.SASLMechanisms.Add.SASL := IdSASLAnonymous; SMTP.SASLMechanisms.Add.SASL := IdSASLExternal; SMTP.SASLMechanisms.Add.SASL := IdSASLLogin; SMTP.SASLMechanisms.Add.SASL := IdSASLPlain; end; { TEmailSenderThread } constructor TEmailSenderThread.Create(CreateSuspended: Boolean); begin inherited Create(CreateSuspended); FreeOnTerminate := True; FSSLEmail := TSSLEmail.Create; end; destructor TEmailSenderThread.Destroy; begin FSSLEmail.Free; inherited; end; procedure TEmailSenderThread.Execute; begin Sleep(FSSLEmail.FedDelaySeconds*1000); if not Terminated then FSSLEmail.SendEmail; end; end.
  4. Zipleyip yükledim bu sefer. Forum yazılımı ile ilgili olabilir SecureMailClient.zip
  5. Oops my bad! yes redirect would destroy the previous session so my answer is wrong.
  6. Tüm kaynak kod SecureMailClient.pas içindedir, detayları görebilirsiniz. AttachFile('pdfdosyasiadi', 'c:\zzzzzzzz\zzz\pdfdosyasi.pdf', 'application/pdf');
  7. Ekteki modülü inceleyin işinize yarayacaktır. Ek göndermek için bu fonsiyonları kullanabilirsiniz: procedure AttachHtmlFile(const AName, AFileName, AContentType, AContentID: string; ATempFile: Boolean = False); procedure AttachTempFile(const AName, AFileName, AContentType: string); procedure AttachFile(const AName, AFileName, AContentType: string); Örnek kullanım: if UniServerModule.ConfigINI.SMTP.ConfigExists then begin EmailSenderThread := TEmailSenderThread.Create(True); with EmailSenderThread.SSLEmail do begin edToEmail := TicketContract.email; edSubject := BRAND_NAME + ' – I dettagli della tua prenotazione'; edHTMLBody.Text := BodyStr; edUserName := UniServerModule.ConfigINI.SMTP.UserName; edPassword := UniServerModule.ConfigINI.SMTP.Password; edSenderEmail := UniServerModule.ConfigINI.SMTP.SenderEmail; edSenderName := UniServerModule.ConfigINI.SMTP.SenderName; edSMTPServer := UniServerModule.ConfigINI.SMTP.Server; edSMTPPort := UniServerModule.ConfigINI.SMTP.Port; if TicketContract.VisitType <> vtRemote then AttachHtmlFile( 'ticket.png', TPath.Combine(UniServerModule.ConfigINI.QRCodeSaveDir, SysUtils.LowerCase(TicketContract.ticketId)+'.png'), 'image/png', 'ticket.png' ); EmailSenderThread.Start; SecureMailClient.pas
  8. One option would be to get the parameter into a property of your main module during first call and redirect default to page www.xyz.de. This way the parameter would be visible only before during the redirection
  9. I had the same issue but I thought that it was by design and did not report it. This is how I solved it (I am not sure if it helps in your case) New form is opened on top of an other form: (Capture1.png) 1) on its UnimFormShow I have UniSession.AddJS('document.getElementById("'+cpMenuContainer.JSId+'").parentElement.style.backgroundColor="rgba(1,1,1,0.5)";'); So that it darkens the previous form's visible area. 2) Also cpMenuContainer has its Color property set 3) I open the frmGetVisitType as Modal
  10. Thanks very much I've checked your demo.
  11. I should have checked the time you posted (its close again). Thanks anyway.
  12. Before going with Angular did you try with unigui's mobile version components?
  13. If your demo web app still active I would like to see its UI. It gives the following message currently: Thanks
  14. So the communication method is standart. If your communication is related to a user session and if you need to repeat the call to this API (like every few seconds) use a TuniTimer events. If it is a one-time call than just call within events available to your forms, standard Delphi way. So there is no ready made components to connect to your devices but you can use THttpClient, TJSONObject etc. to build your JSON and send it over http.
  15. You can integrate on the unigui server side easy. What transport your JSON API using? Is it http?
  16. +1 As the core source code of the library is closed and no deep documentation available, only the advanced members can contribute. This is my main concern of the tool. We all delphi/pascal developers know that pascal source is easier to understand compared to other languages and it is the best documentation since it is always current.
  17. Use this event of the form, you can get the new width/height: UnimFormResize(Sender: TObject);
  18. uniGUI survived for the last 10 years and seems that going to live a long life. It helps us to generate web browser based apps. The directions in software development is decreasing the speed gap between native and web browser based. At some point all browsers will be running native containers. The companies benefit from native apps are those who charge good commissions to publish apps on their native app stores.
  19. What about running a service based app would it be allowed? I mean just a webserver so there is nothing to approve or reject as a UI. And running it like http://127.0.0.1 on the phone, that would do my requirement.
  20. But in this time I need to an other codebase for web, I would prefer a single codebase for Offline/PWA and online web apps.
  21. Birinci sorununuz için yukarıdaki öneriyi deneyin bende çalışmıştı.
  22. İf uniGUI server app cab be targeted/compiled for android or iOS (I mean running unigui exe on mobile device) than at least we could have the same code base so that we can store data on local sqlite while offline, and when internet is available we can communicate with master server to post updates etc., this way we could have same of the business logic running on the mobile device. I am very well aware of the absurd request (in practice) but I am trying to find a way to port my investment with unigui to other platforms otherwise I will be forced to move to other tools.
  23. There is no way to go to old data module. You will get a new data module and using the cookie value you we will check a session table in the database (that you updated in previous unigui session) to retrieve previous session/state like last user login status, open form etc. So that you can continue where you are left off. I use this approach in order not to ask a password at each time user comes back in allowed time. Here is a sample auto login procedure: procedure TfrmMainm.UnimFormCreate(Sender: TObject); begin UniSession.JSCode( 'var sessionCookie = localStorage.getItem("'+SESSION_COOKIE+'");'+ 'param = "'+SESSION_COOKIE+'="+sessionCookie;'+ 'ajaxRequest(frmMainm.form, "UserAutoLogin", [param]);' ); end; procedure TfrmMainm.UnimFormAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); var frmUserLoginm: TfrmUserLoginm; begin if EventName = 'UserAutoLogin' then begin if UniMainModule.UserAutoLogin(Params.Values[SESSION_COOKIE]) then begin ShowMainMenuForm; end else begin frmUserLoginm := TfrmUserLoginm.Create(uniGUIApplication.UniApplication); frmUserLoginm.Show; end; end; end; function TUniMainModule.UserAutoLogin(ASessionCookie: string): Boolean; var qryUser, qryUserSession: TFDQuery; LUserId: Integer; P1: Integer; begin Result := False; P1 := Pos('/', ASessionCookie); if P1 > 0 then begin LUserId := StrToIntDef(Copy(ASessionCookie,P1+1), Length(ASessionCookie)); if LUserId > 0 then begin qryUser := nil; qryUserSession := nil; try qryUser := TFDQuery.Create(nil); FDConnection.Connected := True; qryUser.Connection := FDConnection; with TZUSER do begin qryUser.SQL.Text := 'SELECT *'+ ' FROM '+TABLE+ ' WHERE '+_ID+'=:'+_ID+ ' AND '+_ACTIVE+'=1'; qryUser.ParamByName(_ID).AsInteger := LUserId; qryUser.Open; if not qryUser.Eof then begin with TZUSER_SESSION do begin qryUserSession := TFDQuery.Create(nil); qryUserSession.Connection := FDConnection; qryUserSession.SQL.Text := 'SELECT *'+ ' FROM '+TABLE+ ' WHERE '+_SESSION_COOKIE+'=:'+_SESSION_COOKIE+ ' AND '+_USER_ID+'=:'+_USER_ID; qryUserSession.ParamByName(_SESSION_COOKIE).AsString := ASessionCookie; qryUserSession.ParamByName(_USER_ID).AsInteger := qryUser.FieldByName(TZUSER._ID).AsInteger; qryUserSession.Open; if not qryUserSession.Eof then begin if Now < qryUserSession.FieldByName(_EXPIRES_ON).AsDateTime then begin FUserId := qryUser.FieldByName(TZUSER._ID).AsInteger; FUserType := qryUser.FieldByName(TZUSER._USER_TYPE).AsString; FCompanyId := qryUser.FieldByName(TZUSER._COMPANY_ID).AsInteger; FSessionId := qryUserSession.FieldByName(TZUSER_SESSION._ID).AsInteger; Result := True; end; end; end; end; end; finally qryUser.Free; qryUserSession.Free; end; end; end; end;
  24. If you use a cookie you can associate it with a session state/status and recover where you left off. This is not directly built into unigui but I use this method to achieve what you do in the other tool intraweb
×
×
  • Create New...