iOS Email-Triggered Automation Template

Turn your iPhone into a powerful automation hub using email triggers and Val Town! This template lets you schedule iOS shortcuts to run at specific times by simply sending an email.

🎯 What This Does

This Val creates a system where:

  1. You send an email with a specific subject/sender to your iCloud email
  2. iOS Mail filters detect the email instantly (via push notifications)
  3. An iOS Shortcut automatically triggers
  4. The shortcut calls this Val Town endpoint to schedule an action
  5. Val Town sends you a notification email when it's time to run your automation
  6. Your iOS Shortcut triggers again to perform the scheduled action

🔑 Key Insight: iCloud Push Email

Why iCloud email? iCloud email supports push notifications, meaning emails arrive instantly on your iPhone. This makes it perfect for real-time automation triggers, unlike Gmail which uses periodic polling.

📋 Setup Instructions

Step 1: Set Up Val Town

  1. Fork this Val or copy the code
  2. Update sendEmail.ts to use your email address
  3. Note your HTTP endpoint URL (found in schedule.ts file details)

Step 2: Create iOS Mail Filter

  1. Open Mail app on iPhone
  2. Go to an email from the sender you want to filter (or send yourself a test email)
  3. Tap the sender's email address at the top
  4. Tap "Create VIP" or use a filter app like Mail Rules
  5. Alternatively, create a filter based on subject line containing specific text

Pro Tip: Use a unique subject prefix like [AUTOMATE] to make filtering reliable.

Step 3: Create iOS Shortcut (Trigger)

  1. Open Shortcuts app
  2. Create new Automation
  3. Choose Email trigger
  4. Configure:
    • Sender: specific email address
    • Subject: contains "[AUTOMATE]" (or your prefix)
    • Run Immediately: ON (critical!)
  5. Add action: Get Contents of URL
    • URL: https://your-val-endpoint.web.val.run?minutes=X
    • Method: GET
  6. Parse the email body to extract the minutes value if needed

Step 4: Create iOS Shortcut (Action)

  1. Create another Automation
  2. Choose Email trigger
  3. Configure:
    • Sender: your Val Town email
    • Subject: contains "Scheduled Notification"
    • Run Immediately: ON
  4. Add your actual automation actions here (play music, send message, etc.)

🚀 Usage Examples

Example 1: Delayed Reminder

Send email to yourself:

  • Subject: [AUTOMATE] Remind me in 30 minutes
  • Body: 30

Your shortcut extracts "30" and calls: ?minutes=30

Example 2: Smart Home Delay

  • Subject: [AUTOMATE] Turn off lights in 1 hour
  • Call: ?minutes=60
  • Action shortcut: Triggers HomeKit scene

Example 3: Focus Mode Timer

  • Subject: [AUTOMATE] End focus mode in 90 minutes
  • Call: ?minutes=90
  • Action shortcut: Disables focus mode

🔧 API Reference

Schedule Endpoint

GET /schedule.ts?minutes=X

Parameters:

  • minutes (required): Number of minutes from now to send notification

Response:

{ "success": true, "message": "Email scheduled to send in 30 minutes", "scheduledTime": "2025-11-06T03:35:00.000Z" }

⚙️ Customization

Change Notification Email

Edit sendEmail.ts and update the default email address.

Change Check Frequency

Edit cron.ts interval settings (currently runs every 1 minute).

Add Custom Actions

Modify cron.ts to trigger webhooks, APIs, or other Val Town functions instead of just sending email.

Store Additional Data

The SQLite database can store extra fields like:

  • Action type
  • Custom parameters
  • Original email body
  • Callback URLs

💡 Advanced Ideas

  • Snooze emails: Forward an email with "[SNOOZE 2h]" to get it back in 2 hours
  • Medication reminders: Email yourself from calendar events
  • Parking meters: Email when you park, get reminded before expiration
  • Meeting prep: Email before meetings to trigger prep shortcuts
  • Pomodoro timer: Email yourself to start/end focus sessions

🔒 Security Notes

  • Keep your Val private if it contains sensitive logic
  • Consider adding authentication for production use
  • Email filters should be specific to avoid false triggers
  • Test with small delays first

📚 Resources


Built with ❤️ using Val Town. Fork and customize for your needs!