ESP32 S3 - Gmail

This tutorial shows you how to make the ESP32 S3 send an email through your Gmail account. The message is sent from a Gmail address, but it can be delivered to any email provider.

What you'll build:

  1. An ESP32 S3 project that joins your Wi-Fi network
  2. A sender that logs in to Gmail using an App Password
  3. A notification system that sends email to any address you choose
  4. A starting point you can expand to send emails when a sensor or event is triggered
ESP32 S3 Gmail

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×Alternatively, ESP32 S3 SuperMini Dev Module
1×Alternatively, ESP32 S3 Uno-form Board
1×Alternatively, ESP32 S3 Camera Board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Recommended: Screw Terminal Expansion Board for ESP32 S3
1×Recommended: Breakout Expansion Board for ESP32 S3
1×Recommended: Power Splitter for ESP32 S3

Or you can buy the following kits:

1×DIYables ESP32 S3 Starter Kit (ESP32 S3 included)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Pre-Preparation

Before you start coding, you need a Gmail account and an App Password for it. Please read the points below first.

  • Do not use your main Gmail account. Make a new account just for testing, so your personal account stays safe.
  • The ESP32 S3 code does not use your normal Gmail login password. Instead, it uses a special "App Password" that you create in your Google Account settings.

Follow these steps:

Gmail security
  • Turn on 2-Step Verification. App Passwords are only available when 2-Step Verification is active.
  • Open the Google App Passwords page and make a new app password. Any name is fine.
Google App Passwords
  • Press the Create button. Google will show you a 16-character password like the one below:
Gmail App Passwords
  • Copy this 16-character password and keep it somewhere safe. You will put it into the ESP32 S3 code in the next section.

※ NOTE THAT:

Google sometimes updates the look of its pages. If the steps above do not lead you to "App Passwords," search online for "How to get Google App Passwords" to find the newest guide.

ESP32 S3 Code

The code below sets up the ESP32 S3 to connect to Wi-Fi and send an email through Gmail with the ESP Mail Client library. Before you upload it, enter your Wi-Fi details, the sender Gmail address, the App Password, and the recipient email address.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-gmail */ #include <WiFi.h> #include <ESP_Mail_Client.h> #define WIFI_SSID "YOUR_WIFI_SSID" // CHANGE IT #define WIFI_PASSWORD "YOUR_WIFI_PASSWORD" // CHANGE IT // the sender email credentials #define SENDER_EMAIL "xxxxxx@gmail.com" // CHANGE IT #define SENDER_PASSWORD "xxxx xxxx xxxx xxxx" // CHANGE IT to your Google App password #define RECIPIENT_EMAIL "xxxxxx@gmail.com" // CHANGE IT #define SMTP_HOST "smtp.gmail.com" #define SMTP_PORT 587 SMTPSession smtp; void setup() { Serial.begin(115200); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.print("Connecting to Wi-Fi"); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(300); } Serial.println(); Serial.print("Connected with IP: "); Serial.println(WiFi.localIP()); Serial.println(); String subject = "Email Notification from ESP32 S3"; String textMsg = "This is an email sent from ESP32 S3.\n"; textMsg += "Sensor value: "; textMsg += "15"; // OR replace this value read from a sensor gmail_send(subject, textMsg); } void loop() { // YOUR OTHER CODE HERE } void gmail_send(String subject, String textMsg) { // set the network reconnection option MailClient.networkReconnect(true); smtp.debug(1); smtp.callback(smtpCallback); Session_Config config; // set the session config config.server.host_name = SMTP_HOST; config.server.port = SMTP_PORT; config.login.email = SENDER_EMAIL; config.login.password = SENDER_PASSWORD; config.login.user_domain = F("127.0.0.1"); config.time.ntp_server = F("pool.ntp.org,time.nist.gov"); config.time.gmt_offset = 3; config.time.day_light_offset = 0; // declare the message class SMTP_Message message; // set the message headers message.sender.name = F("ESP32 S3"); message.sender.email = SENDER_EMAIL; message.subject = subject; message.addRecipient(F("To Whom It May Concern"), RECIPIENT_EMAIL); message.text.content = textMsg; message.text.transfer_encoding = "base64"; message.text.charSet = F("utf-8"); message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low; // set the custom message header message.addHeader(F("Message-ID: <abcde.fghij@gmail.com>")); // connect to the server if (!smtp.connect(&config)) { Serial.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s\n", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); return; } if (!smtp.isLoggedIn()) { Serial.println("Not yet logged in."); } else { if (smtp.isAuthenticated()) Serial.println("Successfully logged in."); else Serial.println("Connected with no Auth."); } // start sending Email and close the session if (!MailClient.sendMail(&smtp, &message)) Serial.printf("Error, Status Code: %d, Error Code: %d, Reason: %s\n", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str()); } // callback function to get the Email sending status void smtpCallback(SMTP_Status status) { // print the current status Serial.println(status.info()); // print the sending result if (status.success()) { Serial.println("----------------"); Serial.printf("Message sent success: %d\n", status.completedCount()); Serial.printf("Message sent failed: %d\n", status.failedCount()); Serial.println("----------------\n"); for (size_t i = 0; i < smtp.sendingResult.size(); i++) { // get the result item SMTP_Result result = smtp.sendingResult.getItem(i); Serial.printf("Message No: %d\n", i + 1); Serial.printf("Status: %s\n", result.completed ? "success" : "failed"); Serial.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str()); Serial.printf("Recipient: %s\n", result.recipients.c_str()); Serial.printf("Subject: %s\n", result.subject.c_str()); } Serial.println("----------------\n"); // free the memory smtp.sendingResult.clear(); } }

Detailed Instructions

  • First time using the ESP32 S3? Go through our Getting Started with ESP32 S3 guide before you continue.
  • Plug the ESP32 S3 board into your computer with a USB cable.
  • Launch the Arduino IDE on your computer.
  • Choose the correct ESP32 S3 board and COM port.
  • Click the Library Manager icon on the left side of the Arduino IDE to open it.
  • Type ESP Mail Client in the search box, then look for the ESP Mail Client library by Mobizt.
  • Press the Install button to add the ESP Mail Client library.
  • Search for ESP Mail Client created by Mobizt and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Library Manager
Type:
All
Topic:
All
ESP Mail Client by Mobizt
The library also supported other Arduino devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient. More info
3.4.21
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32S3 Dev Module on COM15
1
  • Copy the code above and paste it into the Arduino IDE.
  • Replace the Wi-Fi name and password with your own by editing the two constants WIFI_SSID and WIFI_PASSWORD.
  • Replace the sender email and password with your own by editing the two constants SENDER_EMAIL and SENDER_PASSWORD.
  • Replace the recipient email with your own by editing the constant RECIPIENT_EMAIL. You can use the same address as the sender.

※ NOTE THAT:

  • The sender email MUST be a Gmail address
  • The sender password is the App Password you created earlier
  • The recipient email can be from any email provider
  • Press the Upload button in the Arduino IDE to send the code to the ESP32 S3.
  • Open the Serial Monitor.
  • Look at the output on the Serial Monitor.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
#### Message sent successfully > C: message sent successfully ---------------- Message sent success: 1 Message sent failed: 0 ---------------- Message No: 1 Status: success Date/Time: Jan 15, 2026 09:21:05 Recipient: xxxxxx@gmail.com Subject: Email Notification from ESP32 S3 ----------------
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2
  • Open the inbox of the recipient email. You should see an email like the one below.
ESP32 S3 sends email
  • Pro Tip: Put your login details in a separate config header file and list that file in .gitignore. This way, you will not share your private information by mistake.

Applications

Sending email from the ESP32 S3 is useful in many IoT alert projects. Below are some popular examples:

  1. Security Alerts: Get an email right away when a motion sensor or door sensor is activated.
  2. Environmental Monitoring: Get notified when temperature, humidity, or air quality goes past a set limit.
  3. Water Leak Detection: Get an alert as soon as a water sensor finds moisture.
  4. Device Status Reports: Send regular emails to confirm that a remote device is still online and working.
  5. Event Logging: Send a summary of sensor readings or events by email on a fixed schedule.

Video Tutorial

The video below walks you through this ESP32 S3 project step by step.

Challenges

After you get basic email sending to work, you can improve the project and learn more. Try these challenges whenever you are ready.

  1. Beginner: Change the code so it sends two emails in one run, each to a different recipient. Then check that both emails arrive.
  2. Intermediate: Connect a push button to the ESP32 S3 and send an email only when the button is pressed, not right after startup.
  3. Advanced: Add a DHT22 temperature and humidity sensor, and send an alert email automatically when the temperature goes above a limit you can set.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!