dotlinux blog

How to Configure Zabbix to Send Email Alerts to Gmail Account

Zabbix is a leading open-source monitoring tool that helps you track the health and performance of servers, networks, and applications. Real-time alerting is one of its most critical features, ensuring you can respond quickly to outages or degradations. While Zabbix supports multiple alert channels, email remains a reliable choice—especially when integrated with Google’s Gmail, which offers robust deliverability and spam protection.

Google’s strict security policies (which block "less secure apps") require a few extra steps to set up Zabbix with Gmail. In this comprehensive guide, we’ll walk you through every step: securing your Gmail account for Zabbix access, configuring Zabbix’s SMTP media type, setting up user alerts, and testing the entire workflow.

2026-03

Table of Contents#

  1. Prerequisites
  2. Step 1: Set Up Gmail for Zabbix Access 2.1 Enable 2-Step Verification 2.2 Generate a Gmail App Password
  3. Step 2: Configure Zabbix SMTP Media Type 3.1 Create a New SMTP Media Type 3.2 Test the SMTP Configuration
  4. Step 3: Assign Media Type to Zabbix Users
  5. Step 4: Configure Zabbix Alert Actions 5.1 Create a Critical Alert Action 5.2 Customize Alert Messages with Macros
  6. Step 5: Test Zabbix Email Alerts
  7. Troubleshooting Common Issues
  8. Conclusion
  9. References

Prerequisites#

Before you begin, ensure you have the following:

  • A running Zabbix Server instance (version 5.0 or later; older versions may have UI differences).
  • A personal Gmail account (for Google Workspace accounts, admin approval may be required for app passwords).
  • Admin access to the Zabbix Frontend and command-line access to the Zabbix server.
  • Sudo/root privileges on the Zabbix server.
  • Basic familiarity with Zabbix concepts (media types, users, actions, triggers).

Step 1: Set Up Gmail for Zabbix Access#

Google blocks SMTP access from unsecure apps, so we need to enable 2-Step Verification (2FA) and generate a special "App Password" for Zabbix.

Enable 2-Step Verification#

  1. Go to your Google Account Security Page.
  2. Under Signing in to Google, click 2-Step Verification.
  3. Follow the prompts to enable 2FA (you’ll need a phone number to receive verification codes).
  4. Once enabled, return to the Security page.

Generate a Gmail App Password#

App Passwords are 16-character codes that let trusted apps access your Gmail account without using your primary password.

  1. On the Security page, click App Passwords (this option only appears if 2FA is enabled).
  2. Re-enter your Gmail password to confirm your identity.
  3. Select Mail from the Select app dropdown.
  4. Select Other (Custom name) from the Select device dropdown and enter "Zabbix Server".
  5. Click Generate to create a 16-character app password. Copy this code—you’ll need it later.
  6. Click Done and store the password securely.

Note: For Google Workspace accounts, check with your admin if app passwords are allowed (some organizations block them for compliance reasons).


Step 2: Configure Zabbix SMTP Media Type#

A media type defines how Zabbix sends alerts. We’ll set up an SMTP media type to use Gmail’s servers.

Create a New SMTP Media Type#

  1. Log in to the Zabbix Frontend as an Admin.
  2. Navigate to Administration > Media Types and click Create media type.
  3. Fill in the following details:
    • Name: "Gmail SMTP Alert" (or a descriptive name of your choice).
    • Type: Select SMTP.
    • SMTP server: smtp.gmail.com
    • SMTP port: 587 (uses STARTTLS for secure communication).
    • SMTP helo: Your server’s fully qualified domain name (FQDN) (e.g., zabbix.yourdomain.com) or gmail.com.
    • SMTP email: Your full Gmail address (e.g., [email protected]).
    • Connection security: STARTTLS
    • Authentication: Check this box.
    • SMTP user: Your full Gmail address.
    • SMTP password: Paste the 16-character app password you generated.
  4. Click Add to save the media type.

Test the SMTP Configuration#

Verify your setup works before proceeding:

  1. In the Media Types list, click the Test icon (paper airplane) next to "Gmail SMTP Alert".
  2. Enter a recipient email address, test subject, and message.
  3. Click Send. Check your inbox (and spam folder) for the test email. If it arrives, your SMTP configuration is valid.

Step 3: Assign Media Type to Zabbix Users#

Zabbix sends alerts to specific users, so you need to assign the Gmail media type to a user or group:

  1. Navigate to Administration > Users and select the user you want to receive alerts (e.g., the default Admin user).
  2. Click the Media tab and then Add.
  3. Fill in:
    • Type: Select "Gmail SMTP Alert".
    • Send to: The email address where alerts should be delivered.
    • When active: 1-7, 00:00-24:00 (24/7 alerts) or customize based on your schedule.
    • Use if severity: Select the trigger severities you want to alert on (e.g., Critical, High, Average).
  4. Click Add to save the media entry, then Update to apply changes to the user.

Step 4: Configure Zabbix Alert Actions#

Actions define when and how Zabbix sends alerts. We’ll create an action to send notifications for critical triggers.

Create a Critical Alert Action#

  1. Navigate to Configuration > Actions and click Create action.
  2. On the Action tab:
    • Name: "Critical Host Alerts via Gmail".
    • Default subject: [{TRIGGER.STATUS}] Zabbix Alert: {TRIGGER.NAME}.
    • Default message:
      Alert Details:
      - Host: {HOST.NAME} ({HOST.IP})
      - Trigger Severity: {TRIGGER.SEVERITY}
      - Trigger Status: {TRIGGER.STATUS}
      - Event Time: {EVENT.DATE} {EVENT.TIME}
      - Trigger URL: {TRIGGER.URL}
      - Problem Details: {ITEM.VALUE1}
      
  3. On the Conditions tab:
    • Click Add and select Trigger severity > equals > Critical. Add more conditions (e.g., exclude test hosts) if needed.
  4. On the Operations tab:
    • Click New > Send message.
    • Select the user/group assigned to the Gmail media type and choose "Gmail SMTP Alert" as the media type.
  5. On the Recovery operations tab:
    • Create a similar operation to send a recovery alert when the trigger returns to OK state (e.g., subject: [{TRIGGER.STATUS}] Zabbix Recovery: {TRIGGER.NAME}).
  6. Click Add to save the action.

Customize Alert Messages with Macros#

Zabbix macros let you include dynamic data in alerts. Useful macros include:

  • {HOST.NAME}: Name of the monitored host.
  • {TRIGGER.SEVERITY}: Severity level of the trigger.
  • {EVENT.DATE}: Date the event occurred.
  • {ITEM.VALUE1}: Value of the item that triggered the alert.

See the Zabbix Macro Documentation for a full list.


Step 5: Test Zabbix Email Alerts#

To ensure alerts work when a trigger fires:

  1. Manual Trigger Test:
    • Navigate to Configuration > Hosts and select a monitored host.
    • Click Triggers > Create trigger.
    • Name it "Test Critical Trigger" and set the expression to {HOSTNAME:system.cpu.load[all,avg1].last()} > 0.1 (most servers have a load above this threshold).
    • Set severity to Critical and save.
    • Wait 5-10 minutes for Zabbix to detect the problem. Check your inbox for the alert.
  2. Log Troubleshooting:
    • If alerts fail, check Zabbix server logs for errors:
      sudo tail -f /var/log/zabbix/zabbix_server.log
    • Look for lines containing "SMTP" or "media type" to identify issues like authentication failures.

Troubleshooting Common Issues#

1. SMTP Authentication Failed#

  • Cause: Incorrect Gmail username or app password.
  • Fix: Verify your full Gmail address is used as the SMTP user and the app password is correct. Ensure 2FA is enabled on your account.

2. Test Email Not Delivered#

  • Cause: Wrong SMTP port or connection security.
  • Fix: Confirm port 587 and STARTTLS are set. If using port 465, switch to SSL. Check if your server’s IP is blocked by Google (send a test email from another device to rule this out).

3. Triggers Not Sending Alerts#

  • Cause: Disabled action, restrictive conditions, or inactive user media.
  • Fix:
    • Ensure the action is enabled (checkbox in Actions list).
    • Verify conditions match the trigger’s severity and host.
    • Check the user media entry’s "When active" settings.

4. Cannot Connect to SMTP Server#

  • Cause: Firewall blocking port 587.
  • Fix: Allow outgoing traffic on port 587:
    sudo ufw allow 587/tcp
    Test connectivity with:
    telnet smtp.gmail.com 587

Conclusion#

Configuring Zabbix to send alerts via Gmail is a straightforward process once you navigate Google’s security requirements. By enabling 2FA, generating an app password, and setting up the SMTP media type, you’ll ensure critical alerts reach your inbox in real time.

Remember to:

  • Keep your app password secure (treat it like any sensitive credential).
  • Test alerts regularly to catch configuration issues early.
  • Customize actions for different severities (e.g., send high-severity alerts to multiple teams).

With this setup, you’ll never miss an important notification about your monitored infrastructure.


References#

  1. Zabbix Official Media Types Documentation
  2. Google Support: Create App Passwords
  3. Zabbix Action Configuration Guide
  4. Zabbix Macro Reference