EmailOS Watch Command Documentation
The mailos watch command monitors scheduled emails and automatically sends them at their scheduled time.
Quick Start
mailos watchThis starts the scheduler daemon that checks for due emails every minute and sends them automatically.
Command-Line Flags
Usage Examples
Continuous Monitoring
Run the scheduler continuously with default 1-minute interval:
mailos watchOutput:
📬 EmailOS Scheduler Started
Checking for scheduled emails every 1m0s
Press Ctrl+C to stop
[12:15:30] Checking for due emails...
No emails due
[12:16:30] Checking for due emails...
📤 Sending 1 scheduled email(s)...
✅ Sent: Meeting Reminder → [[email protected]]Custom Check Interval
Check more frequently for time-sensitive emails:
mailos watch --interval 30sOr check less frequently to save resources:
mailos watch --interval 5mOne-Time Processing
Process all due emails once and exit (useful for cron jobs):
mailos watch --onceVerbose Mode
See detailed SMTP debugging information:
mailos watch --verboseThis shows:
- Detailed check timestamps
- SMTP connection details
- Email sending process
- Error messages if any
Background Execution
Using nohup
Run as a background daemon with logging:
nohup mailos watch --interval 30s > ~/mailos-scheduler.log 2>&1 &Check if running:
ps aux | grep "mailos watch"Stop the scheduler:
pkill -f "mailos watch"Using screen or tmux
Run in a persistent terminal session:
# Using screen
screen -S mailos-scheduler
mailos watch
# Press Ctrl+A then D to detach
# Reattach later
screen -r mailos-scheduler
# Using tmux
tmux new -s mailos-scheduler
mailos watch
# Press Ctrl+B then D to detach
# Reattach later
tmux attach -t mailos-schedulerUsing systemd (Linux)
Create a systemd service for automatic startup:
- Create service file
/etc/systemd/system/mailos-watch.service:
[Unit]
Description=MailOS Email Scheduler
After=network.target
[Service]
Type=simple
User=yourusername
ExecStart=/usr/local/bin/mailos watch --interval 1m
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target- Enable and start the service:
sudo systemctl enable mailos-watch
sudo systemctl start mailos-watch
# Check status
sudo systemctl status mailos-watch
# View logs
journalctl -u mailos-watch -fCron Integration
Use --once flag for cron-based scheduling:
# Edit crontab
crontab -e
# Check every 5 minutes
*/5 * * * * /usr/local/bin/mailos watch --once >> ~/mailos-cron.log 2>&1
# Check every hour
0 * * * * /usr/local/bin/mailos watch --once
# Check every 15 minutes during business hours (9 AM - 5 PM)
*/15 9-17 * * * /usr/local/bin/mailos watch --onceAuto-start on Login
macOS (launchd)
Create ~/Library/LaunchAgents/com.emailos.watch.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.emailos.watch</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/mailos</string>
<string>watch</string>
<string>--interval</string>
<string>1m</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/mailos-watch.log</string>
<key>StandardErrorPath</key>
<string>/tmp/mailos-watch-error.log</string>
</dict>
</plist>Load the service:
launchctl load ~/Library/LaunchAgents/com.emailos.watch.plist
launchctl start com.emailos.watch
# Check status
launchctl list | grep emailosShell Startup Files
Add to ~/.zshrc or ~/.bashrc:
# Start mailos watch if not already running
if ! pgrep -f "mailos watch" > /dev/null; then
nohup mailos watch --interval 30s > /dev/null 2>&1 &
fiHow It Works
- Initialization: Watch command starts and displays startup message
- Polling Loop: At each interval:
- Checks
~/.email/scheduled-emails/directory - Parses JSON files to find emails with
scheduled_at <= current_time - Sends each due email via SMTP
- Moves sent email to
~/.email/sent-scheduled/ - Removes from scheduled queue
- Checks
- Continuous: Repeats until stopped with Ctrl+C (unless
--onceis used)
Error Handling
If an email fails to send:
- Error message is displayed
- Email remains in scheduled queue
- Will be retried on next check interval
- Check logs with
--verboseto debug
Common errors:
- Authentication failed: Check account credentials in
~/.email/config.json - SMTP connection refused: Verify SMTP server settings and network
- Email not found: Email may have been manually deleted from queue
Performance
Resource usage varies with check interval:
--interval 30s: ~2-3% CPU during checks, negligible between--interval 1m: ~1-2% CPU during checks (default)--interval 5m: <1% CPU, minimal resource impact
Memory usage: ~20-30 MB regardless of interval
Monitoring
Check scheduler health:
# Process status
ps aux | grep "mailos watch"
# Log file
tail -f ~/mailos-scheduler.log
# Scheduled email count
ls ~/.email/scheduled-emails/ | wc -l
# Recently sent scheduled emails
ls -lt ~/.email/sent-scheduled/ | head -10Troubleshooting
Emails Not Sending
- Verify watch is running:
ps aux | grep "mailos watch" - Check scheduled emails exist:
mailos schedule-list - Run once with verbose:
mailos watch --once --verbose - Check account authentication:
mailos info
High CPU Usage
- Increase interval:
mailos watch --interval 5m - Check for orphaned processes:
pkill -9 -f "mailos watch" - Verify no infinite loops in error handling
Scheduler Stops Unexpectedly
- Check system logs for crashes
- Run in foreground to see errors:
mailos watch --verbose - Ensure sufficient disk space for logs
- Use systemd or launchd for auto-restart
Related Commands
mailos send- Schedule emails for future sendingmailos schedule-list- List all scheduled emails- Scheduled Sending Guide - Complete scheduling documentation
Files and Directories
| Path | Purpose |
|---|---|
~/.email/scheduled-emails/ | Pending scheduled emails |
~/.email/sent-scheduled/ | Archive of sent scheduled emails |
~/.email/config.json | Account configuration used by watch |
Best Practices
- Run in background: Use screen, tmux, or systemd for persistent operation
- Monitor logs: Set up log rotation to prevent disk fill
- Set appropriate intervals: Balance responsiveness with resource usage
- Use systemd/launchd: For production deployments
- Health checks: Periodically verify scheduler is running
- Graceful restarts: Stop before system shutdown to avoid corrupted state
