email

  • 03 Sep

    Howto trigger email alert after the whole scheduled run completed?

    Q: Is it possible to trigger the email alert in Limagito after the whole scheduled run completed?

    Example : run every 5 mins between 12:00:00 AM and 23:59:59PM

    12:00:00 completed

    12:05:00 completed

    23:55:00 completed

    Email will tigger

    Or is there any other option to send the summary run of job every day?

     

    A: It’s not a default option but we created a small script to achieve this. It does not matter which kind of Source or Destination you are using. So you can add this to any existing Rule.

    >Open the ‘Pascal Script’ setup:

    Limagito File Mover Pascal Script

    >Enable and add the following ‘On Rule Begin’ Pascal Script:

    Begin
      psExitCode:= 1;
      // ... add your code here
      psResetRTLog;
    End.

    Limagito File Mover On Rule Begin Pascal Script

    >Enable and add the following ‘On Rule Begin’ Pascal Script (be sure to adjust the  ctLogPath  constant, we used  C:\Test\Out_Log\  as temporary directory for the log files):

    Var
      tmpDate: String;
      tmpLog: TStringList;
      tmpLogFile: String;
    Const
      ctLogPath = 'C:\Test\Out_Log\'; // Must end with \
    Begin
      psExitCode:= 1;
      // ... add your code here
      tmpDate := FormatDateTime('yyyymmdd', Now);
      tmpLogFile := ctLogPath + 'RTLog_' + tmpDate + '.log';
      //
      tmpLog := TStringList.Create;
      Try
        Try
          If FileExists(tmpLogFile) Then
            tmpLog.LoadFromFile(tmpLogFile);
          // Add
          If psLRT <> '' Then
          Begin
            tmpLog.Add(psLRT);
            // Save
            tmpLog.SaveToFile(tmpLogFile);
          End;     
        Except
          psLogWrite(1, '', 'Error Loading or Saving Log File');
        End;
      Finally
        tmpLog.Free;
      End;
    End.

    Limagito File Mover On Rule end Pascal Script

    >The script creates a RunTime log file with the date as part of the filename (format yyyymmdd). We added  C:\Test\Out_Log\  as temporary directory for the RunTime log files but you can adjust this, always end the ctLogPath constant with a backslash. Nest we’ll create a second rule which will email this file to the desired recipients.

    Limagito File Mover RunTime Log

    >Now you need to add an extra rule with a WIN as Source and SMTP as Destination:

    The Source path of this second rule is the path we used in the previous script. In our case this is ‘C:\Test\Out_Log\’.

    Limagito File Mover WIN as Source

    >Next, please open the File Filter Setup > Advanced Tab > Enable ‘Allow parameters in File Name filter’.

    Limagito File Mover File Filter

    >Add the following File Name Include filter:  *%TCD:[IncDay-1]yyyymmdd:*

    What this filter does is, it looks for a filename with a date part from yesterday because of the [IncDay-1].

    Limagito File Mover File Filter Setup

    So you can trigger this second rule like every 5 minutes since. When a new day starts and this second rule is triggered then it will email the log file from the previous day.

    Limagito File Mover Scan Timer Setup

    >We added SMTP as Destination since our goal was to email the RunTime log file.

    Limagito File Mover Destination Setup

    >Don’t forget to enable ‘Include Source File as Attachment’ so the log file will be included in the email.

    Limagito File Mover SMTP as Destination

    >If you set the Function to ‘Move Files’ then the log file will be deleted after successful SMTP transfer. If you want to keep the RunTime log files then set the Function to ‘Copy Files’ and enable our ‘File Memory’ option.

    Limagito File Mover Function Setup

    Result:

    Limagito File Mover RunTime Log

    #FileTransfer

    If you need any info about this ‘trigger email alert after the whole scheduled run’ question, please let us know.

    Best regards,

    Limagito Team

  • 31 Jul

    Connecting to Office 365 email using IMAP and OAuth2 authentication

    Q: Connecting to Office 365 email using IMAP and OAuth2 authentication.

    Wir versuchen gerade mit Limagito eine Verbindung zu einem MS Office 365 Email Postfach herzustellen und scheitern an der OAuth2 Authntifizierung. Wir wissen nicht genau was alles in die Felder muss.

    A: Best to use a more recent version since we did quite some code changes for IMAP4 as Source and OAuth2 authentication in version v2021.8.5.0 to make it easier to connect to MS Office 365.

    Important: Setup your App Registration in Azure beforehand. Here are the steps:

    1) In the Azure portal, go to Azure Active Directory. In “App registrations” create a “+ New registration”.
    2) Register the app with Redirect URI = “http://localhost:3017”.
    3) Goto “API permissions” to add permissions. For this OAuth2 authorization flow, we’ll add “Delegated permissions”.
    4) Add IMAP.AccessAsUser.All and offline_access permissions.
    5) Go to “Certificates & secrets” and add a new client secret.
    6) In “App registrations”, go to “Endpoints” (located to the right of the “+ New registration” link. Note your endpoints for “OAuth 2.0 authorization endpoint (v2)” and “OAuth 2.0 token endpoint (v2)
    7) Also, just in case, go to your Microsoft 365 admin center (this is not Azure). Go to your Active users. Click on a user to find the “Manage email apps” link. See Microsoft 365 Manage Email Apps
    8) Click on “Manage email apps”. Then make sure the “IMAP” checkbox is checked.

    Next, configuration of our File Mover:

    • Add IMAP4 as Source

    Limagito File Mover IMAP4 as Source

    • IMAP4 Setup. Be sure to select our second API Vendor: ‘Vendor 2 – CK’.

    Limagito File Mover IMAP4 Setup

    • IMAP4 Security Setup (please use version v2021.8.5.0 or higher).

    Limagito File Mover IMAP4 Security Setup

    • IMAP4 Common Setup

    Limagito File Mover IMAP4 Common Setup

    • IMAP4 OAuth2 Setup

    Limagito File Mover IMAP4 OAuth2 setup

    1. Fill in the correct Authorization and Token Url
    2. Enter Client ID and Secret
    3. Adjust your scope to: openid profile offline_access https://outlook.office365.com/IMAP.AccessAsUser.All
      • Provide a SPACE separated list of scopes.
      •  Important: The offline_access scope is needed to get a refresh token.
    4. Set Redirect URI to: http://localhost:3017/
    5. Set Redirect Port to 3017
      • This should be the port in the localhost callback URL for your app.
      • The callback URL would look like “http://localhost:3017/”, if the port number is 3017.
      • The redirect must go to http://localhost:/. It must be localhost, and it cannot be “https”.

    Next, click on the <GET> button.

    Should ‘Windows Defender’ popup, please <Allow access>.

    Limagito File Mover IMAP4 Oauth2

    Your browser will open and ask you for ‘Confirmation’.

    Limagito File Mover IMAP4 OAuth2

    Follow the routine in your browser and accept the authorization request.

    Limagito File Mover IMAP4 OAuth2 Access is granted

    Now you can close the browser. The ‘Refresh’ and ‘Access’ Token in the IMAP4 OAuth2 Setup should contain values. Click <Save>.

    Limagito File Mover IMAP4 OAuth2 Setup

    The IMAP as Source configuration is finished. Just add a Destination and you are ready to go.

    If you need any help with this ‘Office 365 email using IMAP’ request, please let us know.

    Some extra information: ‘Explaining OAuth2 Authentication’.

    The OAuth2 Get Token button does a couple of things:

    1. It starts the OAuth2 Authentication process.
    2. Returns a URL that should be displayed in a browser.
    3. Starts a background thread to receive the redirect callback from the browser.

    The flow of control is like this:

    1. The browser (popped up and displayed by our file mover) automatically navigates to the URL provided by Start Authentication.
    2. The user interactively authorizes the access. In doing so, the response sent back to the browser is a redirect to http://localhost:<someport>/
    3. The browser receives the response, and redirects to the http://localhost:<someport>/
    4. The background thread (= temporary HTTP server using <someport>) is the thing that is listening at and receives the response, and then your OAuth2 is completed.

    The redirect must go to http://localhost:<someport>/. It must be localhost, and it cannot be “https”. If you defined your application’s redirect URL to a web address such as “https://yourdomain.com/something…”, then the background thread is just sitting there waiting for the callback, which never happens (because it went to your web server).

    Note 1: For Microsoft API’s such as for OneDrive, make sure that your App on Microsoft Developer Dashboard, inside Authentication, Redirect URIs, set the app type to Web (not public client). Your desktop app is acting as a web server when receiving the single redirect request.

    Note 2: We used the Scope needed for IMAP. Other examples are:

    • openid profile offline_access https://outlook.office365.com/SMTP.Send
    • openid profile offline_access https://outlook.office365.com/POP.AccessAsUser.All

     

    #FileTransfer

    Best Regards,

    Limagito Team

    By Limagito IMAP4 OAuth2 , , ,
  • 15 Nov

    Q&A 30: I only want to email the latest run time log

    Q: I only want to have email the latest run time. We are trying to come up with a standard email notification format, and we just could not figure out to set up email body as we want. What I would like to want is to have email only to show the result of the latest action.

    A: We are going to use a small Pascal Script to achieve this. Please have a look at the following screenshots.

    Open the Pascal Script Setup of this Rule:

    • Enable ‘On Rule Begin’
    • Add the following ‘On Rule Begin’ Script. Function psRTLog will clear the RunTime Log.
    Begin
      psExitCode:= 1;
      // ... add your code here
      psResetRTLog;
    End.

    Limagito File Mover Reset RunTime Log

    In your email setup you can use  %LRT  (%LRT = Log RunTime) to show the RunTime Log content:

    Limagito File Mover Email Setup

    We decided to make it even easier in our latest version and added an alternative to using Pascal Script. This new build will be available soon.

    Limagito File Mover Clear Log at Rule Begin

    If you need any help with our ‘Clear Log at Rule Begin’ option, please let us know.

    Best Regards,

    Limagito Team

    By Limagito Logging Q&A , , ,
1 2