Last Updated on June 6, 2025
We built different types of ESP32 projects. But this one will stand out because, we are going to communicate in email. Yes by using ESP32 board and its WiFi ability, we are going to send an email using SMTP protocol. You might think its complicated but here is the simple way to do that.
Before that what is SMTP?
Here is the answer in simple words, SMTP stands for Simple Mail Transfer Protocol, it can be used to send emails through internet. Our ESP32 development board can connect to a mail server like Gmail, Amazon SES, Zoho, GMX, etc., and send a message email from your email id to another.
Circuit Diagram
We are going to use only ESP32 board to connect with mail server, so there is no external wiring, If you want to add push button to trigger email, you can connect and write code for that, otherwise we can use simple code and NTP timer to send email. Just connect Your ESP32 board with computer using USB cable.
Components Required
- ESP32 board (here we use DOIT Dev kit V1)
- Wifi Connection
- Gmail account (or any SMTP supported email id)
- PC with Arduino IDE
How it Works?
To Send email from ESP32, connect ESP32 with computer and Upload Arduino code, in code we have WiFi connection setup and email SMTP server Settings and then text email subject and message. When the ESP32 board successfully connected with WiFi and SMTP server then it will send the email message to recipient.
Remember that, you have to write and check the following in Arduino Code for ESP32 board
- WiFi Credentials
- SMTP server Credentials with sender email id and password (in Gmail mostly App password)
- Recipient email id
- Message subject and message.
If you are new to use ESP32 with Arduino IDE then read here to get started.
Requirement & Setup – precheck
Before write Arduino code for ESP32 to send email.
1. Make sure your Arduino IDE have Additional boards ESP32 installed. ESP32 Board in Arduino IDE
2. Install “ReadyMail” by Mobizt library in Arduino IDE. Github page.

3. Configuring your Email Account.
Email Service | SMTP Server Address | Port (SSL) | Port (STARTTLS) | Requires App Password | Notes |
---|---|---|---|---|---|
Gmail | smtp.gmail.com | 465 | 587 | Yes | App password required; 2FA must be enabled |
Yahoo Mail | smtp.mail.yahoo.com | 465 | 587 | Yes | Enable access and generate app password in settings |
Outlook / Hotmail | smtp.office365.com | – | 587 | No | Only STARTTLS supported; SSL not available |
Zoho Mail | smtp.zoho.com | 465 | 587 | Yes | Enable SMTP in Zoho settings; use app password |
iCloud Mail | smtp.mail.me.com | – | 587 | Yes | Only supports STARTTLS; use app password |
Amazon SES | smtp.email-smtp.us-east-1.amazonaws.com (or region-based endpoint) | 465 | 587 | Yes | Use SMTP credentials from AWS SES dashboard |
GMX Mail | mail.gmx.com | 465 | 587 | Yes | Enable SMTP access in GMX account settings |
Here we using Gmail so, the SMTP Configuration will be,
#define SMTP_HOST "smtp.gmail.com" #define SMTP_PORT 465 #define AUTHOR_EMAIL "your_email@gmail.com" #define AUTHOR_PASSWORD "your_app_password"
Mostly Gmail blocks suspected password attempts and different device login request, So that it is must to have App Password for ESP32. Here is the steps to get you own.
Go to Manage Your Google Account > Security then search app password and click open.
Create a new app with new App Name then click Create,
By clicking Create you will get a Password for your App name, like this.
we are going to use this app password for our Gmail email id to send email from ESP32 development board.
Lets Write Code – We have made code with some explanations, if you have more doubts then ask in comment section.
#include <Arduino.h> #include <WiFi.h> #include <WiFiClientSecure.h> #define ENABLE_SMTP #define ENABLE_DEBUG #define READYMAIL_DEBUG_PORT Serial #include <ReadyMail.h> // Wi-Fi & Email Config #define WIFI_SSID "Your WiFi Name" #define WIFI_PASSWORD "Your WiFi Password" //SMTP Server Settings for Gmail - Change it if you are using other email servers #define SMTP_HOST "smtp.gmail.com" #define SMTP_PORT 465 #define AUTHOR_EMAIL "your_sender_email_id@gmail.com" //Put your Sender email id #define AUTHOR_PASSWORD "your_app_password" // App password not gmail password - this is for 2FA enabled gmail email id. #define RECIPIENT_EMAIL "receiver_email@example.com" //Receiver email id WiFiClientSecure client; SMTPClient smtp(client); void smtpStatus(SMTPStatus status) { Serial.println(status.text); } void setup() { Serial.begin(115200); delay(1000); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.print("Connecting to Wi-Fi"); while (WiFi.status() != WL_CONNECTED) { delay(300); Serial.print("."); } Serial.println("\nConnected to Wi-Fi!"); Serial.println("IP Address: " + WiFi.localIP().toString()); client.setInsecure(); // Insecure, for dev testing configTime(19800, 0, "pool.ntp.org", "time.nist.gov"); Serial.print("Waiting for NTP time..."); while (time(nullptr) < 100000) { delay(1000); Serial.print("."); } Serial.println(); smtp.connect(SMTP_HOST, SMTP_PORT, smtpStatus, true); if (!smtp.isConnected()) return; smtp.authenticate(AUTHOR_EMAIL, AUTHOR_PASSWORD, readymail_auth_password); if (!smtp.isAuthenticated()) return; SMTPMessage msg; msg.headers.add(rfc822_from, AUTHOR_EMAIL); msg.headers.add(rfc822_to, RECIPIENT_EMAIL); msg.headers.add(rfc822_subject, " Email from ESP32 (Real Time)"); msg.headers.addCustom("X-Priority", "1"); msg.headers.addCustom("Importance", "High"); String body = "Hello,\r\n\r\n"; body += "This is an email sent from my ESP32 board!\r\n"; body += "It includes real-time data and avoids spam folder.\r\n\r\n"; msg.text.body(body); msg.timestamp = time(nullptr); smtp.send(msg, "SUCCESS,FAILURE"); // smtp.disconnect(); // REMOVE or comment this out } void loop() {}
After Successful uploading check the serial monitor and your recipient email id.
In Recipient email id inbox. If not showing here, you may check Spam folder (it may be flagged as spam when you are not using time NTP).