N8n automation: Send SMTP email notification if some one remotely access to your computer

N8n automation: Send SMTP email notification if some one remotely access to your computer

In this tutorial, we’ll learn how to use Task Scheduler in Windows 10 or 11 to automate the execution of a script that triggers an n8n webhook. This webhook sends a SMTP email notification containing specific parameters whenever someone remotely connects to your computer. Let’s walk through the process step by step.

Step 1: Create an n8n automation:

You can download a sample workflow here:

Step 2: Write a PowerShell script:

# Define the base URL and webhook ID
$urlBase = "URL to n8n webhook"
$webhookId = "n8n webhook id"
$status="unlock"

# Construct the full webhook URL
$webhookUrl = "${urlBase}/${webhookId}?status=${status}"

# Trigger the webhook
Invoke-WebRequest -Uri $webhookUrl -Method GET

Or you can download a sample script here:

Step 3: Create A Task Scheduler:

  1. Open Task Scheduler.
  2. right click and select "create new task...":
  1. In the new task dialog, follow these steps:
  • Create a Trigger:
    • Navigate to the Triggers tab and click the "New…" button.
    • Set Begin the task to "On connection to user session".
If you want the task to trigger when someone remotely accesses your computer, ensure the "Connection from remote computer" option is selected.
  • Create an Action:
    • Go to the Actions tab and click the "New…" button.
    • Set the action to "Start a Program".
    • In the Program/script field, add: powershell.exe.
    • Add the following to the Add arguments (optional) field:
      -file "path\to\trigger-n8n-webhook-script.ps1" -username "%UserName%"

Save the task by clicking OK.

How It Works

Once everything is set up:

  1. When someone remotely connects to your computer, Task Scheduler triggers the PowerShell script.
  2. The script sends an HTTP GET request to the n8n webhook, passing parameters like the status (unlock).
  3. n8n processes the webhook and sends a SMTP email notification with the provided information.

Conclusion

This simple automation leverages Windows Task Scheduler, PowerShell, and n8n to keep you informed about remote connections to your computer.

Feel free to share your thoughts or ask questions in the comments below. If you have custom requirements, you can adapt the script or the workflow to suit your needs!

Do you enjoy this blog post?

Read more