Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

MBS FileMaker Plugin Example Databases

GMail oAuth SMTP

All examples are included with download of MBS FileMaker Plugin.

GMail oAuth SMTP.fmp12

Overview
Tables 1
Relationships 0
Layouts 1
Scripts 8
Value Lists 0
Custom Functions 0
Custom Menus 24
File Options
Default custom menu set [Standard FileMaker Menus]
Default theme Apex Blue
When opening file
Minimum allowed version 12.0
Login using Account Name; Account= Admin
Allow user to save password On
Require iOS passcode Off
Show Sign-in fields On
Switch to layout Off
Hide all toolbars Off
Script triggers
OnFirstWindowOpen Off
OnLastWindowClose Off
OnWindowOpen Off
OnWindowClose Off
OnFileAVPlayerChange Off
OnWindowTransaction Off
Thumbnail Settings
Generate Thumbnails On; Temporary

 

Tables

Table Name
Statistics
Comments
Occurrences in Relationship Graph
GMail oAuth SMTP
21 fields defined, 1 record
GMail oAuth SMTP

Fields

Table Name: GMail oAuth SMTP - 21 Fields
Field Name Type Options Comments On Layouts In Relationships In Scripts In Value Lists
PrimaryKey Normal, Text Auto-Enter: Validation:
  • Only during data entry
  • Not empty
  • Unique
  • Strict validation
Storage:
  • Repetitions: 1
  • Indexing: Minimal
  • Automatically create indexes as needed
  • Index Language: Unicode Raw
Unique identifier of each record in this table
          CreationTimestamp Normal, Timestamp Auto-Enter:
          • Creation timestamp
          Validation:
          • Only during data entry
          • Strict data type: 4 digit year
          • Not empty
          • Strict validation
          Storage:
          • Repetitions: 1
          • Indexing: None
          • Automatically create indexes as needed
          • Index Language: German
          Date and time each record was created
                  CreatedBy Normal, Text Auto-Enter:
                  • Creation account name
                  Validation:
                  • Only during data entry
                  • Not empty
                  • Strict validation
                  Storage:
                  • Repetitions: 1
                  • Indexing: None
                  • Automatically create indexes as needed
                  • Index Language: German
                  Account name of the user who created each record
                          ModificationTimestamp Normal, Timestamp Auto-Enter:
                          • Modification timestamp
                          Validation:
                          • Only during data entry
                          • Strict data type: 4 digit year
                          • Not empty
                          • Strict validation
                          Storage:
                          • Repetitions: 1
                          • Indexing: None
                          • Automatically create indexes as needed
                          • Index Language: German
                          Date and time each record was last modified
                                  ModifiedBy Normal, Text Auto-Enter:
                                  • Modification account name
                                  Validation:
                                  • Only during data entry
                                  • Not empty
                                  • Strict validation
                                  Storage:
                                  • Repetitions: 1
                                  • Indexing: None
                                  • Automatically create indexes as needed
                                  • Index Language: German
                                  Account name of the user who last modified each record
                                          Debug Normal, Text Auto-Enter:
                                          • Allow editing
                                          Validation:
                                          • Only during data entry
                                          Storage:
                                          • Repetitions: 1
                                          • Indexing: None
                                          • Automatically create indexes as needed
                                          • Index Language: German
                                              URL Normal, Text Auto-Enter:
                                              • Allow editing
                                              Validation:
                                              • Only during data entry
                                              Storage:
                                              • Repetitions: 1
                                              • Indexing: None
                                              • Automatically create indexes as needed
                                              • Index Language: German
                                                  CURL Debug Normal, Text Auto-Enter:
                                                  • Allow editing
                                                  Validation:
                                                  • Only during data entry
                                                  Storage:
                                                  • Repetitions: 1
                                                  • Indexing: None
                                                  • Automatically create indexes as needed
                                                  • Index Language: German
                                                      CURL Result Normal, Text Auto-Enter:
                                                      • Allow editing
                                                      Validation:
                                                      • Only during data entry
                                                      Storage:
                                                      • Repetitions: 1
                                                      • Indexing: None
                                                      • Automatically create indexes as needed
                                                      • Index Language: German
                                                          access_token Normal, Text Auto-Enter:
                                                          • Allow editing
                                                          Validation:
                                                          • Only during data entry
                                                          Storage:
                                                          • Repetitions: 1
                                                          • Indexing: None
                                                          • Automatically create indexes as needed
                                                          • Index Language: German
                                                              Answer Normal, Text Auto-Enter:
                                                              • Allow editing
                                                              Validation:
                                                              • Only during data entry
                                                              Storage:
                                                              • Repetitions: 1
                                                              • Indexing: None
                                                              • Automatically create indexes as needed
                                                              • Index Language: German
                                                                  ClientID Normal, Text Auto-Enter:
                                                                  • Allow editing
                                                                  Validation:
                                                                  • Only during data entry
                                                                  Storage:
                                                                  • Repetitions: 1
                                                                  • Indexing: None
                                                                  • Automatically create indexes as needed
                                                                  • Index Language: German
                                                                      ClientSecret Normal, Text Auto-Enter:
                                                                      • Allow editing
                                                                      Validation:
                                                                      • Only during data entry
                                                                      Storage:
                                                                      • Repetitions: 1
                                                                      • Indexing: None
                                                                      • Automatically create indexes as needed
                                                                      • Index Language: German
                                                                          TenantID Normal, Text Auto-Enter:
                                                                          • Allow editing
                                                                          Validation:
                                                                          • Only during data entry
                                                                          Storage:
                                                                          • Repetitions: 1
                                                                          • Indexing: None
                                                                          • Automatically create indexes as needed
                                                                          • Index Language: German
                                                                                From Email Normal, Text Auto-Enter:
                                                                                • Allow editing
                                                                                Validation:
                                                                                • Only during data entry
                                                                                Storage:
                                                                                • Repetitions: 1
                                                                                • Indexing: None
                                                                                • Automatically create indexes as needed
                                                                                • Index Language: German
                                                                                    To Email Normal, Text Auto-Enter:
                                                                                    • Allow editing
                                                                                    Validation:
                                                                                    • Only during data entry
                                                                                    Storage:
                                                                                    • Repetitions: 1
                                                                                    • Indexing: None
                                                                                    • Automatically create indexes as needed
                                                                                    • Index Language: German
                                                                                        From Name Normal, Text Auto-Enter:
                                                                                        • Allow editing
                                                                                        Validation:
                                                                                        • Only during data entry
                                                                                        Storage:
                                                                                        • Repetitions: 1
                                                                                        • Indexing: None
                                                                                        • Automatically create indexes as needed
                                                                                        • Index Language: German
                                                                                            To Name Normal, Text Auto-Enter:
                                                                                            • Allow editing
                                                                                            Validation:
                                                                                            • Only during data entry
                                                                                            Storage:
                                                                                            • Repetitions: 1
                                                                                            • Indexing: None
                                                                                            • Automatically create indexes as needed
                                                                                            • Index Language: German
                                                                                                Subject Normal, Text Auto-Enter:
                                                                                                • Allow editing
                                                                                                Validation:
                                                                                                • Only during data entry
                                                                                                Storage:
                                                                                                • Repetitions: 1
                                                                                                • Indexing: None
                                                                                                • Automatically create indexes as needed
                                                                                                • Index Language: German
                                                                                                    Email Text Normal, Text Auto-Enter:
                                                                                                    • Allow editing
                                                                                                    Validation:
                                                                                                    • Only during data entry
                                                                                                    Storage:
                                                                                                    • Repetitions: 1
                                                                                                    • Indexing: None
                                                                                                    • Automatically create indexes as needed
                                                                                                    • Index Language: German
                                                                                                        refresh_token Normal, Text Auto-Enter:
                                                                                                        • Allow editing
                                                                                                        Validation:
                                                                                                        • Only during data entry
                                                                                                        Storage:
                                                                                                        • Repetitions: 1
                                                                                                        • Indexing: None
                                                                                                        • Automatically create indexes as needed
                                                                                                        • Index Language: German

                                                                                                            Layout Objects: GMail oAuth SMTP

                                                                                                            Regular Fields

                                                                                                            Field Name: GMail oAuth SMTP::Debug
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 89 pt
                                                                                                            • Left: 893 pt
                                                                                                            • Bottom: 174 pt
                                                                                                            • Right: 1146 pt
                                                                                                            • Anchoring: Left and Right, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Field Name: GMail oAuth SMTP::URL
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 182 pt
                                                                                                            • Left: 893 pt
                                                                                                            • Bottom: 267 pt
                                                                                                            • Right: 1146 pt
                                                                                                            • Anchoring: Left and Right, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Field Name: GMail oAuth SMTP::CURL Debug
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 275 pt
                                                                                                            • Left: 893 pt
                                                                                                            • Bottom: 360 pt
                                                                                                            • Right: 1146 pt
                                                                                                            • Anchoring: Left and Right, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Field Name: GMail oAuth SMTP::CURL Result
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 368 pt
                                                                                                            • Left: 893 pt
                                                                                                            • Bottom: 453 pt
                                                                                                            • Right: 1146 pt
                                                                                                            • Anchoring: Left and Right, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Field Name: GMail oAuth SMTP::access_token
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 554 pt
                                                                                                            • Left: 893 pt
                                                                                                            • Bottom: 639 pt
                                                                                                            • Right: 1146 pt
                                                                                                            • Anchoring: Left and Right, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Field Name: GMail oAuth SMTP::Answer
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 461 pt
                                                                                                            • Left: 893 pt
                                                                                                            • Bottom: 546 pt
                                                                                                            • Right: 1146 pt
                                                                                                            • Anchoring: Left and Right, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Field Name: GMail oAuth SMTP::ClientID
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 726 pt
                                                                                                            • Left: 138 pt
                                                                                                            • Bottom: 757 pt
                                                                                                            • Right: 391 pt
                                                                                                            • Anchoring: Left, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Field Name: GMail oAuth SMTP::ClientSecret
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 761 pt
                                                                                                            • Left: 138 pt
                                                                                                            • Bottom: 792 pt
                                                                                                            • Right: 391 pt
                                                                                                            • Anchoring: Left, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Field Name: GMail oAuth SMTP::From Email
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 726 pt
                                                                                                            • Left: 506 pt
                                                                                                            • Bottom: 757 pt
                                                                                                            • Right: 759 pt
                                                                                                            • Anchoring: Left, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Field Name: GMail oAuth SMTP::To Email
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 796 pt
                                                                                                            • Left: 506 pt
                                                                                                            • Bottom: 827 pt
                                                                                                            • Right: 759 pt
                                                                                                            • Anchoring: Left, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Field Name: GMail oAuth SMTP::From Name
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 761 pt
                                                                                                            • Left: 506 pt
                                                                                                            • Bottom: 792 pt
                                                                                                            • Right: 759 pt
                                                                                                            • Anchoring: Left, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Field Name: GMail oAuth SMTP::To Name
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 831 pt
                                                                                                            • Left: 506 pt
                                                                                                            • Bottom: 862 pt
                                                                                                            • Right: 759 pt
                                                                                                            • Anchoring: Left, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Field Name: GMail oAuth SMTP::Subject
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 726 pt
                                                                                                            • Left: 866 pt
                                                                                                            • Bottom: 757 pt
                                                                                                            • Right: 1119 pt
                                                                                                            • Anchoring: Left, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Field Name: GMail oAuth SMTP::Email Text
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 761 pt
                                                                                                            • Left: 866 pt
                                                                                                            • Bottom: 862 pt
                                                                                                            • Right: 1119 pt
                                                                                                            • Anchoring: Left, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Field Name: GMail oAuth SMTP::refresh_token
                                                                                                            Field Properties Coordinates Field Format Field Behavior Quick Find
                                                                                                            • Top: 866 pt
                                                                                                            • Left: 138 pt
                                                                                                            • Bottom: 936 pt
                                                                                                            • Right: 759 pt
                                                                                                            • Anchoring: Left, Top
                                                                                                            Field Format:
                                                                                                            • Edit Box
                                                                                                            Field Behavior:
                                                                                                            • Allow field to be entered: In Find mode, In Browse mode
                                                                                                            • Touch keyboard type: Default for Data Type
                                                                                                            • Go to next field using: Tab key
                                                                                                            Yes

                                                                                                            Buttons

                                                                                                            Button Properties Coordinates Script/Script Step
                                                                                                              Type:
                                                                                                            • Text: Open Scripts
                                                                                                            • Top: 17 pt
                                                                                                            • Left: 772 pt
                                                                                                            • Bottom: 48 pt
                                                                                                            • Right: 959 pt
                                                                                                            • Anchoring: Left, Top
                                                                                                            Open Script Workspace

                                                                                                            Web Viewer Controls

                                                                                                            Web Viewer Control Properties Coordinates Web Address
                                                                                                              Additional Properties:
                                                                                                            • Allow interaction with web viewer content
                                                                                                            • Display progress bar
                                                                                                            • Display status messages
                                                                                                            • Top: 89 pt
                                                                                                            • Left: 10 pt
                                                                                                            • Bottom: 722 pt
                                                                                                            • Right: 759 pt
                                                                                                            • Anchoring: Left, Top
                                                                                                            "about:blank"

                                                                                                            Script Hierarchy

                                                                                                            Start Authentication
                                                                                                            WebHookReceived
                                                                                                            Query Token
                                                                                                            Extract Access Token
                                                                                                            Send Email
                                                                                                            Clear
                                                                                                            Logout from WebViewer
                                                                                                            Refresh Token

                                                                                                            Next Script: [WebHookReceived]
                                                                                                            Script Name Start Authentication
                                                                                                            Run script with full access privileges Off
                                                                                                            Siri Shortcut Visible Off
                                                                                                            Include In Menu Yes
                                                                                                            Layouts that use this script
                                                                                                              Scripts that use this script
                                                                                                                Script Definition
                                                                                                                Script Steps
                                                                                                                • #Start a web view for the callback
                                                                                                                • If [ IsEmpty ( $$WebHooks ) ]
                                                                                                                • #setup callback
                                                                                                                • Set Variable [ $$WebHooks; Value:MBS("WebHook.Create") ]
                                                                                                                • Set Variable [ $r; Value:MBS("WebHook.Listen"; $$WebHooks; 9999) ]
                                                                                                                • Set Variable [ $r; Value:MBS("WebHook.SetScript"; $$WebHooks; Get(FileName); "WebHookReceived") ]
                                                                                                                • Set Variable [ $text; Value:"<html><p>Request arrived.</p></html>" ]
                                                                                                                • Set Variable [ $text; Value:"HTTP/1.1 200 OK¶Server: MyServer 1.0¶Connection: close¶Content-Type: text/html¶Content-Length: 36¶¶" & $text ]
                                                                                                                • Set Variable [ $text; Value:MBS( "Text.ReplaceNewline"; $Text; 3 ) ]
                                                                                                                • Set Variable [ $r; Value:MBS("WebHook.SetAutoAnswer"; $$Webhooks; $text; "UTF-8") ]
                                                                                                                • End If
                                                                                                                • #Now load URL in browser to have user login:
                                                                                                                • #Please signup your own Cloud Project with the redirect URI below and the client secret.
                                                                                                                • Set Variable [ $clientID; Value:Trim(GMail oAuth SMTP::ClientID) ]
                                                                                                                • Set Variable [ $TenantID; Value:Trim(GMail oAuth SMTP::TenantID) ]
                                                                                                                • Set Variable [ $redirectURI; Value:"http://localhost:9999/" ]
                                                                                                                • Set Variable [ $redirectURI; Value:MBS("Text.EncodeURLComponent"; $redirectURI; "UTF-8") ]
                                                                                                                • Set Variable [ $scope; Value:"https://mail.google.com/" ]
                                                                                                                • Set Variable [ $scope; Value:MBS("Text.EncodeURLComponent"; $scope; "UTF-8") ]
                                                                                                                • Set Variable [ $URL; Value:"https://accounts.google.com/o/oauth2/v2/auth?response_type=code&scope=" & $scope & "&redirect_uri=" & $redirectURI & "&client_id=" & $clientID & "&state=test&prompt=consent" ]
                                                                                                                • #let web viewer be Safari
                                                                                                                • Set Variable [ $r; Value:MBS("WebView.SetCustomUserAgent"; "web"; "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15") ]
                                                                                                                • #Load the URL
                                                                                                                • Set Variable [ $r; Value:MBS( "WebView.LoadURL"; "web"; $URL) ]
                                                                                                                • #show for debugging
                                                                                                                • Set Field [ GMail oAuth SMTP::URL; $URL ]
                                                                                                                Fields used in this script
                                                                                                                Scripts used in this script
                                                                                                                  Layouts used in this script
                                                                                                                    Tables used in this script
                                                                                                                    Table occurrences used by this script
                                                                                                                    Custom Functions used by this script
                                                                                                                      Custom menu set used by this script

                                                                                                                        Previous Script: [Start Authentication] Next Script: [Query Token]
                                                                                                                        Script Name WebHookReceived
                                                                                                                        Run script with full access privileges Off
                                                                                                                        Siri Shortcut Visible Off
                                                                                                                        Include In Menu No
                                                                                                                        Layouts that use this script
                                                                                                                          Scripts that use this script
                                                                                                                            Script Definition
                                                                                                                            Script Steps
                                                                                                                            • Set Variable [ $WebRequest; Value:Get(ScriptParameter) ]
                                                                                                                            • #we got the answer
                                                                                                                            • Set Variable [ $URLComponents; Value:MBS( "WebRequest.URLComponents"; $WebRequest ) ]
                                                                                                                            • If [ Position ( JSONGetElement ( $URLComponents ; "RelativeURL" ); "favicon.ico"; 1; 1 ) > 0 ]
                                                                                                                            • #ignore query for favicon
                                                                                                                            • Exit Script [ ]
                                                                                                                            • End If
                                                                                                                            • Set Field [ GMail oAuth SMTP::Answer; $URLComponents ]
                                                                                                                            • #and show full request for debugging
                                                                                                                            • Set Variable [ $Text; Value:MBS( "Text.ReplaceNewline"; MBS("WebRequest.GetRawData"; $WebRequest; "UTF-8"); 1) ]
                                                                                                                            • Set Field [ GMail oAuth SMTP::Debug; $Text ]
                                                                                                                            • #free the webhook and request
                                                                                                                            • Set Variable [ $r; Value:MBS("WebRequest.Release"; $WebRequest) ]
                                                                                                                            • Set Variable [ $r; Value:MBS("WebHook.Release"; $$WebHooks) ]
                                                                                                                            • Set Variable [ $$WebHooks; Value:"" ]
                                                                                                                            • #clear web viewer
                                                                                                                            • Set Variable [ $r; Value:MBS( "WebView.LoadURL"; "web"; "about:blank") ]
                                                                                                                            • #Now continue with query token
                                                                                                                            • Perform Script [ “Query Token” ]
                                                                                                                            Fields used in this script
                                                                                                                            Scripts used in this script
                                                                                                                            Layouts used in this script
                                                                                                                              Tables used in this script
                                                                                                                              Table occurrences used by this script
                                                                                                                              Custom Functions used by this script
                                                                                                                                Custom menu set used by this script

                                                                                                                                  Previous Script: [WebHookReceived] Next Script: [Extract Access Token]
                                                                                                                                  Script Name Query Token
                                                                                                                                  Run script with full access privileges Off
                                                                                                                                  Siri Shortcut Visible Off
                                                                                                                                  Include In Menu No
                                                                                                                                  Layouts that use this script
                                                                                                                                    Scripts that use this script
                                                                                                                                    Script Definition
                                                                                                                                    Script Steps
                                                                                                                                    • Set Variable [ $URLComponents; Value:GMail oAuth SMTP::Answer ]
                                                                                                                                    • Set Variable [ $Parameters; Value:JSONGetElement ( $URLComponents ; "Parameters" ) ]
                                                                                                                                    • Set Variable [ $code; Value:JSONGetElement ( $Parameters ; "code" ) ]
                                                                                                                                    • Set Variable [ $state; Value:JSONGetElement ( $Parameters ; "state" ) ]
                                                                                                                                    • Set Variable [ $session_state; Value:JSONGetElement ( $Parameters ; "session_state" ) ]
                                                                                                                                    • #if we got a code, we continue to query the access code
                                                                                                                                    • If [ Length ( $code ) > 0 ]
                                                                                                                                    • Set Variable [ $clientID; Value:Trim ( GMail oAuth SMTP::ClientID ) ]
                                                                                                                                    • Set Variable [ $clientSecret; Value:Trim(GMail oAuth SMTP::ClientSecret) ]
                                                                                                                                    • Set Variable [ $URL; Value:"https://oauth2.googleapis.com/token" ]
                                                                                                                                    • Set Variable [ $redirectURI; Value:MBS("Text.EncodeURLComponent"; "http://localhost:9999/"; "UTF-8") ]
                                                                                                                                    • Set Variable [ $Data; Value:"code=" & $code & "&client_id=" & $clientID & "&client_secret=" & $clientSecret & "&grant_type=authorization_code" & "&redirect_uri=" & $redirectURI ]
                                                                                                                                    • Set Variable [ $curl; Value:MBS("CURL.New") ]
                                                                                                                                    • Set Variable [ $result; Value:MBS("CURL.SetOptionURL"; $curl; $URL) ]
                                                                                                                                    • Set Variable [ $result; Value:MBS("CURL.SetOptionPostFields"; $curl; $Data; "UTF-8") ]
                                                                                                                                    • Set Variable [ $result; Value:MBS("CURL.SetOptionHTTPHeader"; $curl; "application/x-www-form-urlencoded") ]
                                                                                                                                    • Set Variable [ $result; Value:MBS("CURL.Perform"; $curl) ]
                                                                                                                                    • #Pick Result
                                                                                                                                    • Set Variable [ $code; Value:MBS( "CURL.GetResponseCode"; $curl ) ]
                                                                                                                                    • Set Variable [ $resultText; Value:MBS("CURL.GetResultAsText"; $curl) ]
                                                                                                                                    • Set Variable [ $debugText; Value:MBS("CURL.GetDebugAsText"; $curl) ]
                                                                                                                                    • Set Field [ GMail oAuth SMTP::CURL Debug; $DebugText ]
                                                                                                                                    • Set Field [ GMail oAuth SMTP::CURL Result; $resultText ]
                                                                                                                                    • If [ $result = "OK" and $code = 200 ]
                                                                                                                                    • Perform Script [ “Extract Access Token” ]
                                                                                                                                    • Else [ ]
                                                                                                                                    • Show Custom Dialog [ Title: "SMTP"; Message: "Failed to query token."; Default Button: “OK”, Commit: “Yes” ]
                                                                                                                                    • End If
                                                                                                                                    • Set Variable [ $result; Value:MBS("CURL.Cleanup"; $curl) ]
                                                                                                                                    • End If
                                                                                                                                    Fields used in this script
                                                                                                                                    Scripts used in this script
                                                                                                                                    Layouts used in this script
                                                                                                                                      Tables used in this script
                                                                                                                                      Table occurrences used by this script
                                                                                                                                      Custom Functions used by this script
                                                                                                                                        Custom menu set used by this script

                                                                                                                                          Previous Script: [Query Token] Next Script: [Send Email]
                                                                                                                                          Script Name Extract Access Token
                                                                                                                                          Run script with full access privileges Off
                                                                                                                                          Siri Shortcut Visible Off
                                                                                                                                          Include In Menu No
                                                                                                                                          Layouts that use this script
                                                                                                                                            Scripts that use this script
                                                                                                                                            Script Definition
                                                                                                                                            Script Steps
                                                                                                                                            • Set Variable [ $Result; Value:GMail oAuth SMTP::CURL Result ]
                                                                                                                                            • #get access token
                                                                                                                                            • Set Variable [ $token_type; Value:JSONGetElement ( $Result ; "token_type" ) ]
                                                                                                                                            • Set Variable [ $scope; Value:JSONGetElement ( $Result ; "scope" ) ]
                                                                                                                                            • Set Variable [ $expires_in; Value:JSONGetElement ( $Result ; "expires_in" ) ]
                                                                                                                                            • Set Variable [ $ext_expires_in; Value:JSONGetElement ( $Result ; "ext_expires_in" ) ]
                                                                                                                                            • Set Variable [ $access_token; Value:JSONGetElement ( $Result ; "access_token" ) ]
                                                                                                                                            • Set Variable [ $refresh_token; Value:JSONGetElement ( $Result ; "refresh_token" ) ]
                                                                                                                                            • If [ Length ( $access_token ) > 0 ]
                                                                                                                                            • Set Field [ GMail oAuth SMTP::access_token; $access_token ]
                                                                                                                                            • If [ Length ( $refresh_token ) > 0 ]
                                                                                                                                            • #we only get one, if offline_access scope is set
                                                                                                                                            • Set Field [ GMail oAuth SMTP::refresh_token; $refresh_token ]
                                                                                                                                            • End If
                                                                                                                                            • Show Custom Dialog [ Title: "Got token!"; Default Button: “OK”, Commit: “Yes” ]
                                                                                                                                            • End If
                                                                                                                                            Fields used in this script
                                                                                                                                            Scripts used in this script
                                                                                                                                              Layouts used in this script
                                                                                                                                                Tables used in this script
                                                                                                                                                Table occurrences used by this script
                                                                                                                                                Custom Functions used by this script
                                                                                                                                                  Custom menu set used by this script

                                                                                                                                                    Previous Script: [Extract Access Token] Next Script: [Clear]
                                                                                                                                                    Script Name Send Email
                                                                                                                                                    Run script with full access privileges Off
                                                                                                                                                    Siri Shortcut Visible Off
                                                                                                                                                    Include In Menu Yes
                                                                                                                                                    Layouts that use this script
                                                                                                                                                      Scripts that use this script
                                                                                                                                                        Script Definition
                                                                                                                                                        Script Steps
                                                                                                                                                        • #create email
                                                                                                                                                        • Set Variable [ $EmailID; Value:MBS("SendMail.CreateEmail") ]
                                                                                                                                                        • Set Variable [ $r; Value:MBS("SendMail.SetFrom"; $EmailID; Trim(GMail oAuth SMTP::From Email); Trim(GMail oAuth SMTP::From Name)) ]
                                                                                                                                                        • Set Variable [ $r; Value:MBS("SendMail.SetPlainText"; $EmailID; GMail oAuth SMTP::Email Text) ]
                                                                                                                                                        • Set Variable [ $r; Value:MBS("SendMail.SetSubject"; $EmailID; GMail oAuth SMTP::Subject) ]
                                                                                                                                                        • Set Variable [ $r; Value:MBS("SendMail.SetSMTPServer"; $EmailID; "smtp.gmail.com") ]
                                                                                                                                                        • Set Variable [ $r; Value:MBS("SendMail.SetSMTPUsername"; $EmailID; Trim(GMail oAuth SMTP::From Email)) ]
                                                                                                                                                        • Set Variable [ $r; Value:MBS("SendMail.AddTO"; $EmailID; Trim (GMail oAuth SMTP::To Email); Trim (GMail oAuth SMTP::To Name)) ]
                                                                                                                                                        • Set Variable [ $curl; Value:MBS("CURL.New") ]
                                                                                                                                                        • Set Variable [ $r; Value:MBS("SendMail.PrepareCURL"; $EmailID; $curl) ]
                                                                                                                                                        • #Maybe use alternative SMTP port?
                                                                                                                                                        • Set Variable [ $r; Value:MBS("CURL.SetOptionPort"; $curl; 587) ]
                                                                                                                                                        • #This turns TLS on and requires connection to be encrypted
                                                                                                                                                        • Set Variable [ $r; Value:MBS("CURL.SetOptionUseSSL"; $curl; 3) ]
                                                                                                                                                        • #force TLS v1.2
                                                                                                                                                        • Set Variable [ $r; Value:MBS("CURL.SetOptionSSLVersion"; $curl; 6) ]
                                                                                                                                                        • #This disables certificate verification, so we accept any:
                                                                                                                                                        • Set Variable [ $r; Value:MBS("CURL.SetOptionSSLVerifyHost"; $curl; 0) ]
                                                                                                                                                        • Set Variable [ $r; Value:MBS("CURL.SetOptionSSLVerifyPeer"; $curl; 0) ]
                                                                                                                                                        • #put in token
                                                                                                                                                        • Set Variable [ $r; Value:MBS("CURL.SetOptionXOAuth2Bearer"; $curl; GMail oAuth SMTP::access_token) ]
                                                                                                                                                        • #Better with certificates if you have some:
                                                                                                                                                        • // Set Variable [ $r; Value:MBS( "CURL.SetOptionCAInfo"; $curl; "/Library/FileMaker Server/certificates.pem") ]
                                                                                                                                                        • // Set Variable [ $r; Value:MBS("CURL.SetOptionSSLVerifyHost"; $curl; 2) ]
                                                                                                                                                        • // Set Variable [ $r; Value:MBS("CURL.SetOptionSSLVerifyPeer"; $curl; 1) ]
                                                                                                                                                        • #Run the transfer
                                                                                                                                                        • Set Variable [ $r; Value:MBS("CURL.Perform"; $curl) ]
                                                                                                                                                        • #get debug messages
                                                                                                                                                        • Set Field [ GMail oAuth SMTP::CURL Debug; MBS("CURL.GetDebugAsText"; $curl; "UTF-8") ]
                                                                                                                                                        • Set Variable [ $r; Value:MBS("CURL.Release"; $curl) ]
                                                                                                                                                        • # Cleanup
                                                                                                                                                        • Set Variable [ $r; Value:MBS("SendMail.Release"; $EmailID) ]
                                                                                                                                                        Fields used in this script
                                                                                                                                                        Scripts used in this script
                                                                                                                                                          Layouts used in this script
                                                                                                                                                            Tables used in this script
                                                                                                                                                            Table occurrences used by this script
                                                                                                                                                            Custom Functions used by this script
                                                                                                                                                              Custom menu set used by this script

                                                                                                                                                                Previous Script: [Send Email] Next Script: [Logout from WebViewer]
                                                                                                                                                                Script Name Clear
                                                                                                                                                                Run script with full access privileges Off
                                                                                                                                                                Siri Shortcut Visible Off
                                                                                                                                                                Include In Menu Yes
                                                                                                                                                                Layouts that use this script
                                                                                                                                                                  Scripts that use this script
                                                                                                                                                                    Script Definition
                                                                                                                                                                    Script Steps
                                                                                                                                                                    • Set Field [ GMail oAuth SMTP::Debug; "" ]
                                                                                                                                                                    • Set Field [ GMail oAuth SMTP::URL; "" ]
                                                                                                                                                                    • Set Field [ GMail oAuth SMTP::CURL Debug; "" ]
                                                                                                                                                                    • Set Field [ GMail oAuth SMTP::CURL Result; "" ]
                                                                                                                                                                    • Set Field [ GMail oAuth SMTP::access_token; "" ]
                                                                                                                                                                    • Set Field [ GMail oAuth SMTP::Answer; "" ]
                                                                                                                                                                    Fields used in this script
                                                                                                                                                                    Scripts used in this script
                                                                                                                                                                      Layouts used in this script
                                                                                                                                                                        Tables used in this script
                                                                                                                                                                        Table occurrences used by this script
                                                                                                                                                                        Custom Functions used by this script
                                                                                                                                                                          Custom menu set used by this script

                                                                                                                                                                            Previous Script: [Clear] Next Script: [Refresh Token]
                                                                                                                                                                            Script Name Logout from WebViewer
                                                                                                                                                                            Run script with full access privileges Off
                                                                                                                                                                            Siri Shortcut Visible Off
                                                                                                                                                                            Include In Menu Yes
                                                                                                                                                                            Layouts that use this script
                                                                                                                                                                              Scripts that use this script
                                                                                                                                                                                Script Definition
                                                                                                                                                                                Script Steps
                                                                                                                                                                                • #In case you are logged in for the webviewer and you can't login with a new account, use this script to logout
                                                                                                                                                                                • #let web viewer be Safari
                                                                                                                                                                                • Set Variable [ $r; Value:MBS("WebView.SetCustomUserAgent"; "web"; "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15") ]
                                                                                                                                                                                • #Load the URL
                                                                                                                                                                                • Set Variable [ $URL; Value:"https://accounts.google.com/Logout" ]
                                                                                                                                                                                • Set Variable [ $r; Value:MBS( "WebView.LoadURL"; "web"; $URL) ]
                                                                                                                                                                                • #show for debugging
                                                                                                                                                                                • Set Field [ GMail oAuth SMTP::URL; $URL ]
                                                                                                                                                                                Fields used in this script
                                                                                                                                                                                Scripts used in this script
                                                                                                                                                                                  Layouts used in this script
                                                                                                                                                                                    Tables used in this script
                                                                                                                                                                                    Table occurrences used by this script
                                                                                                                                                                                    Custom Functions used by this script
                                                                                                                                                                                      Custom menu set used by this script

                                                                                                                                                                                        Previous Script: [Logout from WebViewer]
                                                                                                                                                                                        Script Name Refresh Token
                                                                                                                                                                                        Run script with full access privileges Off
                                                                                                                                                                                        Siri Shortcut Visible Off
                                                                                                                                                                                        Include In Menu Yes
                                                                                                                                                                                        Layouts that use this script
                                                                                                                                                                                          Scripts that use this script
                                                                                                                                                                                            Script Definition
                                                                                                                                                                                            Script Steps
                                                                                                                                                                                            • If [ Length ( GMail oAuth SMTP::refresh_token ) = 0 ]
                                                                                                                                                                                            • Show Custom Dialog [ Title: "Can't refresh the token."; Message: "Please get a token first!"; Default Button: “OK”, Commit: “Yes” ]
                                                                                                                                                                                            • Exit Script [ ]
                                                                                                                                                                                            • End If
                                                                                                                                                                                            • Set Variable [ $TenantID; Value:Trim(GMail oAuth SMTP::TenantID) ]
                                                                                                                                                                                            • Set Variable [ $clientID; Value:Trim ( GMail oAuth SMTP::ClientID ) ]
                                                                                                                                                                                            • Set Variable [ $clientSecret; Value:Trim(GMail oAuth SMTP::ClientSecret) ]
                                                                                                                                                                                            • Set Variable [ $URL; Value:"https://oauth2.googleapis.com/token" ]
                                                                                                                                                                                            • Set Variable [ $redirectURI; Value:MBS("Text.EncodeURLComponent"; "http://localhost:9999/"; "UTF-8") ]
                                                                                                                                                                                            • Set Variable [ $scope; Value:"https://mail.google.com/" ]
                                                                                                                                                                                            • Set Variable [ $Data; Value:"client_id=" & $clientID & "&scope=" & $scope & "&refresh_token=" & GMail oAuth SMTP::refresh_token & "&client_secret=" & $clientSecret & "&grant_type=refresh_token" & "&redirect_uri=" & $redirectURI ]
                                                                                                                                                                                            • Set Variable [ $curl; Value:MBS("CURL.New") ]
                                                                                                                                                                                            • Set Variable [ $result; Value:MBS("CURL.SetOptionURL"; $curl; $URL) ]
                                                                                                                                                                                            • Set Variable [ $result; Value:MBS("CURL.SetOptionPostFields"; $curl; $Data; "UTF-8") ]
                                                                                                                                                                                            • Set Variable [ $result; Value:MBS("CURL.SetOptionHTTPHeader"; $curl; "application/x-www-form-urlencoded") ]
                                                                                                                                                                                            • Set Variable [ $result; Value:MBS("CURL.Perform"; $curl) ]
                                                                                                                                                                                            • #Pick Result
                                                                                                                                                                                            • Set Variable [ $code; Value:MBS( "CURL.GetResponseCode"; $curl ) ]
                                                                                                                                                                                            • If [ $result = "OK" and $code = 200 ]
                                                                                                                                                                                            • Set Variable [ $resultText; Value:MBS("CURL.GetResultAsText"; $curl) ]
                                                                                                                                                                                            • Set Variable [ $debugText; Value:MBS("CURL.GetDebugAsText"; $curl) ]
                                                                                                                                                                                            • Set Field [ GMail oAuth SMTP::CURL Debug; $DebugText ]
                                                                                                                                                                                            • Set Field [ GMail oAuth SMTP::CURL Result; $resultText ]
                                                                                                                                                                                            • Perform Script [ “Extract Access Token” ]
                                                                                                                                                                                            • Else [ ]
                                                                                                                                                                                            • Show Custom Dialog [ Title: "SMTP"; Message: "Failed to query token."; Default Button: “OK”, Commit: “Yes” ]
                                                                                                                                                                                            • End If
                                                                                                                                                                                            • Set Variable [ $result; Value:MBS("CURL.Cleanup"; $curl) ]
                                                                                                                                                                                            Fields used in this script
                                                                                                                                                                                            Scripts used in this script
                                                                                                                                                                                            Layouts used in this script
                                                                                                                                                                                              Tables used in this script
                                                                                                                                                                                              Table occurrences used by this script
                                                                                                                                                                                              Custom Functions used by this script
                                                                                                                                                                                                Custom menu set used by this script

                                                                                                                                                                                                  Download example: GMail oAuth SMTP

                                                                                                                                                                                                  Used functions: