Email Tool
Email Tool
Section titled “Email Tool”TL;DR (Quick Start)
Section titled “TL;DR (Quick Start)”Configure Gmail SMTP:
/tool e-mail set address=smtp.gmail.com port=587 tls=starttls \Send a test email:
Send email with attachment:
Gmail/Office365
Gmail and Office365 require App Passwords, not regular passwords. OAuth2 is not supported by RouterOS.
Overview
Section titled “Overview”What this covers: Configuring SMTP email on your MikroTik router for sending notifications, alerts, and automated reports.
When to use this:
- Sending backup files via email
- Netwatch alerts when hosts go up/down
- Scheduled status reports
- Script-triggered notifications
- System event alerts
How it works:
- Configure SMTP server settings (
/tool e-mail set) - Send emails using
/tool e-mail send - Optionally integrate with scheduler, netwatch, or scripts
Key concepts:
- SMTP server: External mail server that relays your messages
- TLS/STARTTLS: Encryption for secure mail transmission
- App Password: Special password for services that don’t support OAuth2
- Plain authentication: Only auth method supported by RouterOS
Prerequisites:
- SMTP server access (Gmail, Office365, or your own)
- App Password for Gmail/Office365 (regular passwords won’t work)
- Outbound access to SMTP ports (25, 465, or 587)
Part 1: Basic Configuration
Section titled “Part 1: Basic Configuration”Configure SMTP Server
Section titled “Configure SMTP Server”/tool e-mail set address=smtp.yourdomain.com port=587 tls=starttls \Configuration Parameters
Section titled “Configuration Parameters”| Parameter | Default | Description |
|---|---|---|
address | 0.0.0.0 | SMTP server address |
port | 25 | SMTP server port |
user | (empty) | Authentication username |
password | (empty) | Authentication password |
from | <> | Sender email address |
tls | no | Encryption: no/yes/starttls |
TLS Modes
Section titled “TLS Modes”| Mode | Port | Description |
|---|---|---|
no | 25 | No encryption (not recommended) |
starttls | 587 | Upgrade to TLS after connecting |
yes | 465 | Implicit TLS from start |
Verify Configuration
Section titled “Verify Configuration”/tool e-mail printExample output:
address: smtp.gmail.com port: 587 from: [email protected] user: [email protected] password: **************** tls: starttlsPart 2: Sending Emails
Section titled “Part 2: Sending Emails”Basic Email
Section titled “Basic Email” body="This is a test message from MikroTik"Email with Attachment
Section titled “Email with Attachment” body="Daily backup attached" file=router-backup.backupMultiple Attachments
Section titled “Multiple Attachments” file=export.rsc,router-backup.backupEmail with CC
Section titled “Email with CC” subject="Alert" body="Important notification"Send parameters
Section titled “Send parameters”| Parameter | Description |
|---|---|
to | Recipient email (required) |
cc | CC recipients (comma-separated) |
subject | Email subject line |
body | Message body (plain text only) |
file | Attachment(s) (comma-separated) |
Part 3: Email Provider Setup
Section titled “Part 3: Email Provider Setup”Gmail requires an App Password (16-character code):
- Go to Google Account → Security → 2-Step Verification → App Passwords
- Generate a new app password for “Mail”
- Use this password in RouterOS:
/tool e-mail set address=smtp.gmail.com port=587 tls=starttls \ password="xxxx-xxxx-xxxx-xxxx"Office 365
Section titled “Office 365”- Enable SMTP AUTH in Office 365 Admin Center for the mailbox
- May need to disable security defaults or use app password
/tool e-mail set address=smtp.office365.com port=587 tls=starttls \ password="yourpassword"Provider quick reference
Section titled “Provider quick reference”| Provider | Server | Port | TLS |
|---|---|---|---|
| Gmail | smtp.gmail.com | 587 | starttls |
| Gmail (SSL) | smtp.gmail.com | 465 | yes |
| Office 365 | smtp.office365.com | 587 | starttls |
| Outlook.com | smtp-mail.outlook.com | 587 | starttls |
| Yahoo | smtp.mail.yahoo.com | 587 | starttls |
Part 4: Automated Email Scripts
Section titled “Part 4: Automated Email Scripts”Backup Email Script
Section titled “Backup Email Script”Send daily backup via email:
/system scheduler add name="daily-backup-email" interval=1d on-event={ /system backup save name=daily-backup :delay 2s subject=([/system identity get name] . " Daily Backup") \ body=("Backup created: " . [/system clock get date]) \ file=daily-backup.backup}Netwatch Email Alert
Section titled “Netwatch Email Alert”Send email when host goes down or up:
/tool netwatch add host=8.8.8.8 interval=30s \ down-script={ subject="ALERT: Host 8.8.8.8 DOWN" \ body=("Host went down at " . [/system clock get time]) } \ up-script={ subject="RECOVERED: Host 8.8.8.8 UP" \ body=("Host recovered at " . [/system clock get time]) }System Status Report
Section titled “System Status Report”:local cpuload [/system resource get cpu-load]:local freemem [/system resource get free-memory]:local uptime [/system resource get uptime]:local name [/system identity get name]
subject="$name Status Report" \ body="CPU Load: $cpuload%\nFree Memory: $freemem\nUptime: $uptime"Error Handling
Section titled “Error Handling”:do {} on-error={ :log warning "Email send failed"}Part 5: Advanced Configuration
Section titled “Part 5: Advanced Configuration”Override Server Per-Send
Section titled “Override Server Per-Send”Send via different server without changing global config:
server=smtp.backup.com port=587 tls=starttls \ subject="Via Backup Server" body="Sent through backup SMTP"Using IP Instead of Hostname
Section titled “Using IP Instead of Hostname”Some configurations require IP address:
# Resolve hostname:put [:resolve smtp.gmail.com]
# Use IP in config/tool e-mail set address=74.125.136.108Certificate Verification
Section titled “Certificate Verification”For self-signed certificates:
/tool e-mail set certificate-verification=noTroubleshooting
Section titled “Troubleshooting”Problem 1: Gmail “AUTH Failed”
Section titled “Problem 1: Gmail “AUTH Failed””Symptom: Authentication error with Gmail.
Cause: Using regular Gmail password; OAuth2 not supported.
Solution: Generate App Password:
- Go to Google Account → Security
- Enable 2-Step Verification
- Go to App Passwords → Generate
- Use the 16-character code as password
Problem 2: TLS Handshake Failed
Section titled “Problem 2: TLS Handshake Failed”Symptom: “TLS handshake failed” error.
Cause: Wrong TLS mode for the port.
Solution:
- Port 587: Use
tls=starttls - Port 465: Use
tls=yes - Port 25: Use
tls=no(not recommended)
Problem 3: Connection Timeout
Section titled “Problem 3: Connection Timeout”Symptoms: Email send times out or hangs.
Causes:
- Firewall blocking outbound SMTP
- DNS resolution failure
- Wrong server address or port
Solutions:
# Test DNS resolution:put [:resolve smtp.gmail.com]
# Test connectivity/tool fetch url="https://smtp.gmail.com" keep-result=no
# Try using IP instead of hostname/tool e-mail set address=74.125.136.108Problem 4: Email Not Received
Section titled “Problem 4: Email Not Received”Symptom: No errors but email doesn’t arrive.
Causes:
- Spam filtering
- SPF/DKIM failures
- Relay restrictions
Solutions:
- Check spam/junk folder
- Verify SPF records for sending domain
- Use authenticated SMTP relay
Problem 5: Netwatch Email Fails on Link Down
Section titled “Problem 5: Netwatch Email Fails on Link Down”Symptom: Down notification doesn’t send.
Cause: Trying to send email over the link that’s down.
Solutions:
- Use backup route for SMTP server
- Add delay for failover:
:delay 10sbefore send - Send via different interface
Problem 6: Office 365 Authentication Failed
Section titled “Problem 6: Office 365 Authentication Failed”Symptom: Cannot authenticate to Office 365.
Cause: SMTP AUTH disabled by default.
Solution:
- Go to Microsoft 365 Admin Center
- Users → Active Users → Select user
- Mail → Email apps → Enable “Authenticated SMTP”
Verification commands
Section titled “Verification commands”# Check email configuration/tool e-mail print
# Send test email
# Check logs for email activity/log print where topics~"e-mail"
# Enable debug logging/system logging add topics=e-mail,debug action=memoryRelated topics
Section titled “Related topics”Automation
Section titled “Automation”Common Email Uses
Section titled “Common Email Uses”- System Backup - email backup notifications
- Logging - email on critical log events
- VRRP - failover notifications
Prerequisites
Section titled “Prerequisites”- DNS Server - DNS for SMTP server resolution
- NTP Client - accurate timestamps
Reference
Section titled “Reference”Official Documentation
Section titled “Official Documentation”Quick reference commands
Section titled “Quick reference commands”# Configure SMTP/tool e-mail set address=smtp.server.com port=587 tls=starttls \
# View configuration/tool e-mail print
# Send basic email
# Send with attachment
# Send with override settings user="altuser" password="altpass" subject="Test" body="Via alternate server"v6 syntax differences
Section titled “v6 syntax differences”# v6 TLS configuration/tool e-mail set start-tls=yes port=587# or for implicit TLS/tool e-mail set start-tls=tls-only port=465Summary
Section titled “Summary”Email Tool enables notifications and alerts from RouterOS:
- SMTP setup - Configure server, port, TLS, and credentials
- Gmail/O365 - Require App Passwords (OAuth2 not supported)
- Send emails - Basic messages, attachments, CC recipients
- Automation - Scheduler, Netwatch, and script integration
- Troubleshooting - Check TLS mode, firewall, DNS, and spam filters
Key points:
- Use
tls=starttlsfor port 587,tls=yesfor port 465 - Gmail/Office365 require App Passwords, not regular passwords
- Add
:delay 2safter creating files before sending as attachments - Netwatch down alerts may fail if sending over the down link
- Only plain text emails are supported (no HTML)