Source: https://mokxi.com/libraries/esp-mail-client
Updated: 2026-11-22

Libraries / Network

Arduino library · Network

# ESP Mail Client: send an email from an ESP32

Yes, you can build with the ESP Mail Client library online in Mokxi with nothing to install. Its hardware is not simulated, so a sketch says plainly that it cannot reach the device. The example below, "Sending an email, and why it cannot go out here", runs on the ESP32-C3-DevKitM-1.

Run the example in Mokxi See the calls

Built in on Mokxi: #include <ESP_Mail_Client.h> and it builds, with nothing to install. Free, and no account needed.

## What ESP Mail Client does

ESP Mail Client, also by Mobizt, sends email from an ESP32 or ESP8266 over SMTP and can read a mailbox over IMAP. The common use is an alert: the door opened, the freezer warmed up, the plant needs water, and a message lands in your inbox with no app or cloud dashboard in between.

Sending takes four objects. An SMTPSession is the connection. A Session_Config holds the server, port, login email and password. An SMTP_Message holds the sender, subject, recipients and body. MailClient.sendMail(&smtp, &message) puts them together, and a status callback plus smtp.sendingResult tell you how it went. Gmail, Outlook and most providers want TLS on port 465 or STARTTLS on 587.

In Mokxi the library compiles and the Send_Text example runs on an ESP32-C3, but no mail goes out: SMTP needs a TCP connection with TLS to the mail server, which neither the simulated network nor Real internet mode carries. smtp.connect() and sendMail() return false with errorCode() -1 and an errorReason() that explains, and the serial monitor says so. IMAP is not included. For a notification you can see in the simulator, POST to http://api.mokxi/ with HTTPClient.

Library Manager name | ESP Mail Client

Author | Mobizt

Include | #include <ESP_Mail_Client.h>

Boards | ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, ESP32-S3-CAM, ESP8266 NodeMCU

In the simulator | Builds and runs, and says plainly that the hardware behind it is not simulated.

## Install it

It builds on ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, ESP32-S3-CAM, ESP8266 NodeMCU.

In Mokxi it is built in: #include <ESP_Mail_Client.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "ESP Mail Client" by Mobizt from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add ESP Mail Client to lib_deps in PlatformIO. Mokxi follows the calls of release 3.4.24, so a sketch written here builds there too.

What to know in the simulator: SMTP needs a TCP connection with TLS to the mail server, which neither the simulated network nor Real internet mode carries, so smtp.connect() and sendMail() return false with errorCode() -1 and an errorReason() that says why, and one Serial line says it too. IMAP is not here. HTTPClient with http://api.mokxi/ shows a notification request in the Cloud panel.

- ESP32-C3
- ESP32-C6
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32 DevKit
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- ESP32-S3-DevKitC-1
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- ESP32-S3-CAM
- ESP8266 NodeMCU

## The calls you will use

In the order a sketch meets them.

### SMTPSession smtp

The SMTP connection object, declared globally.

### Session_Config config

The server and login: set config.server.host_name, config.server.port, config.login.email and config.login.password.

### SMTP_Message message

The email itself: message.sender.email, message.subject and message.text.content, plus recipients.

### message.addRecipient(F("Me"), "me@example.com")

Adds a recipient by display name and address. Call it once per recipient.

### smtp.callback(smtpCallback)

Registers a function given an SMTP_Status as sending progresses, with success() and info() to print.

### smtp.connect(&config)

Connects and logs in. Returns false on failure; smtp.errorReason() says why.

### MailClient.sendMail(&smtp, &message)

Sends the message and closes the session. Returns true when the server accepted it.

### smtp.errorReason()

The last error as a String, with errorCode() and statusCode() for the numbers.

## Example: Sending an email, and why it cannot go out here

On the ESP32-C3-DevKitM-1. It runs in the browser exactly as printed.

sketch.ino · ESP32-C3-DevKitM-1

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### authentication failed, or 535 Username and Password not accepted (Gmail)

Gmail no longer accepts your normal password from devices like this. Turn on 2-Step Verification for the account, create an app password in its security settings, and put that 16-character password in config.login.password.

### Connection error, Error Code: -1

The board could not open a TLS connection to the mail server: check the host name, use port 465 for SSL or 587 for STARTTLS, and make sure WiFi is up and the clock is set. In Mokxi this is the expected result, since SMTP is not carried.

### sendMail() says success but nothing arrives

The server accepted the message and then filtered it. Look in the spam folder, make sure the sender address is the account you logged in with, and avoid sending dozens of identical alerts in a few minutes.

## Questions and answers

### Can I send email from Mokxi at all?

Not over SMTP. The sketch compiles and runs so you can check it, then tells you it cannot connect. For a cloud notification you can watch, use HTTPClient to POST to http://api.mokxi/ and look in the Cloud panel.

## Keep going

### Learn

- ESP32 IoT Projects for Final Year Students
- ESP32 Not Connecting to WiFi: Causes and Fixes

### More network libraries

- PubSubClient
- MQTT
- Blynk
- ThingSpeak
- WiFiManager
- WiFi, HTTPClient and WebServer (ESP32 core)
- WebSockets
- NTPClient

Every built-in library · Open the editor

## Try ESP Mail Client without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
