Overview

This ESP32 Send Email Notifications shows you how to turn an ESP32 microcontroller into a smart email alert system using the CircuitDigest Cloud Email API. Instead of wireless alerts or displays, your device will send real email notifications whenever a trigger—like a sensor threshold—is crossed. You could use this for proximity alerts, safety warnings, intrusion detection, or general IoT notifications with minimal hardware.

What You’ll Build

A real-time email notification system that monitors distance with an ultrasonic sensor and sends an email when the measured distance goes below a set threshold. Email formatting and delivery is handled by the CircuitDigest Cloud Email Notification API, eliminating complex mail server configuration.

Hardware Requirements

  • ESP32 development board – connects to Wi-Fi and runs your logic.

  • Ultrasonic distance sensor (e.g., HC-SR04) – detects object proximity.

  • Breadboard and jumper wires – for tidy prototyping.

Setup & API Configuration

1. Register & Link Email

  1. Sign up or log into CircuitDigest Cloud.

  2. Navigate to the Email Notification API section.

  3. Add your email and verify it with the OTP sent to your inbox.

  4. Link up to five addresses and choose or create an email template.

CircuitDigest Cloud provides 80+ templates and lets you preview how your alerts will appear once delivered.

Wiring the Ultrasonic Sensor

Connect the trigger and echo pins of the sensor to two GPIOs on the ESP32 (e.g., GPIO 32 for trigger and GPIO 33 for echo). Provide proper power and ground, and verify your sensor’s voltage requirements (3.3 V or 5 V).

How It Works

  1. The ESP32 connects to your Wi-Fi network.

  2. The ultrasonic sensor continually measures distance.

  3. If the measured value drops below your threshold (e.g., 30 cm), it triggers an email.

  4. A secure HTTPS request (JSON) is sent to the CircuitDigest Cloud Email API with your chosen template and dynamic data (like sensor values).

  5. The cloud platform handles delivery instantly to the verified email address.

This setup removes the need for mail server details like SMTP configuration and SSL certificates on your device.

Core Code Highlights

  • Wi-Fi and secure client setup using WiFi.h and WiFiClientSecure.h.

  • Distance measurement through timed ultrasonic pulses.

  • JSON email payload containing your email template variables.

  • Trigger logic to avoid multiple emails per event.

Make sure to replace placeholders like ssid, password, apiKey, toEmail, and templateID with your actual credentials and template info.

Tips & Troubleshooting

  • No emails received? Verify your API key, linked email, and spam filters.

  • Incorrect email content? Check your template ID and request JSON structure.

  • Power issues? ESP32 can reset under load while sending HTTPS; use a stable supply.

  • Sensor errors? Double-check wiring and ensure correct pins are defined.

Expand Your Project

Once you’ve mastered this basic alert system, you can:

  • Add multiple sensors (temperature, gas, motion) and conditional alerts.

  • Include images, logs, or location data in your email payloads.

  • Combine email with SMS or push notifications for robust alerts.

  • Store sensor readings for cloud analytics and visualisations.

Why This Matters

With minimal hardware and a cloud API simplifying delivery, this system lets you add real-world alerting capabilities to any ESP32 projects. Whether you are building smart security, automation, or monitoring solutions, cloud-based email notifications make sure important events never go unnoticed.