Please follow the below steps to send mail to the users who haven't logged in for the last X days:
Step 1: Navigate to Reports--->New Query Report--->Execute the given query--->Now the report will be generated.
Step 2: Save the report with a name under any folder or create a new folder.
Step 3: Navigate to Custom Functions--->Schedule custom function.Copy and paste the given script and change the following details in the script--->change the query report name and mail address as per the your requirement.
Step 4: Navigate to Automation--->Custom Schedule-->In the arguments select the saved query report and select the start date and time as per your requirement and execute the custom function.
Step 5: So each time schedule runs--->Mail will be sent to the following users.