A comprehensive Arduino library for sending emails via SMTP with full support for attachments, multiple recipients, and secure connections (SSL/TLS and STARTTLS).
Author: Renzo Mischianti
Website: www.mischianti.org
GitHub: @xreef
Complete tutorials and articles available on mischianti.org:
- 🌐 EMailSender Library Home - Main library page with all articles
- 📖 Library Forum & Support - Community support and discussions
- 📧 ESP32: Send email with attachments (Gmail, Yahoo, Outlook) - Complete guide for ESP32
- 🔐 ESP32: Secure email with SSL/TLS and attachments - SSL/TLS configuration
- 📎 ESP32: Manage SPIFFS and send attachments - SPIFFS file attachments
- 💾 ESP32: LittleFS filesystem and email attachments - LittleFS integration
- 📁 ESP32: FFAT filesystem and large file attachments - FFAT for large files
- 📧 ESP8266: Send email with attachments - Complete guide for ESP8266
- 📎 ESP8266: Manage SPIFFS and send attachments - SPIFFS integration
- 💾 ESP8266: LittleFS filesystem and email attachments - LittleFS support
- 📧 Arduino: Send email with attachments (Ethernet shield) - Arduino with ENC28J60
- 🔐 Arduino: Secure SSL/TLS email with Ethernet - SSL configuration for Arduino
- 📎 Arduino: SD card attachments with Ethernet - SD card integration
- 📡 Arduino: WiFiNINA shield and email sending - WiFiNINA shield
- 📧 STM32: Send email with W5500 Ethernet - STM32 with W5500
- 🔐 STM32: Secure SSL/TLS email with W5500 - SSL/TLS for STM32
- 📎 STM32: SPI Flash attachments with email - SPI Flash integration
- 🌐 STM32: Send email with ENC28J60 - ENC28J60 Ethernet
- 📧 Raspberry Pi Pico W: Send email with attachments - Pico W WiFi
- 💾 Raspberry Pi Pico: LittleFS and email attachments - LittleFS integration
- 🔐 STARTTLS vs SSL/TLS: Understanding secure email - NEW! Security protocols explained
- 📮 Gmail App Passwords: Setup guide - Configure Gmail for Arduino
- 🛠️ Troubleshooting email sending issues - Common problems and solutions
- Features
- Supported Platforms
- Supported Network Interfaces
- Supported Storage Systems
- Installation
- Basic Usage
- Changelog v4.0.0
- ✅ Send emails via SMTP with authentication
- ✅ Multiple recipients (To, Cc, Bcc)
- ✅ HTML and plain text email formats
- ✅ File attachments from various storage systems
- ✅ Base64 encoding for attachments
- ✅ Custom sender name and email address
- ✅ Subject and message body customization
- ✅ STARTTLS support (Port 587) - NEW!
- ✅ Implicit SSL/TLS (Port 465)
- ✅ Multiple authentication methods:
- AUTH LOGIN (default)
- AUTH PLAIN (SASL)
- CRAM-MD5 (ESP32 only)
- ✅ Internal SSLClient for STARTTLS on ESP32/ESP8266
- ✅ OpenSLab SSLClient (BearSSL) for Ethernet shields
- Multiple network interfaces (WiFi, Ethernet, WiFiNINA)
- Automatic IP resolution
- Connection retry logic
- Flexible client configuration
| Platform | WiFi | Ethernet | SSL/TLS | STARTTLS |
|---|---|---|---|---|
| ESP32 | ✅ | ✅ | ✅ | ✅ |
| ESP8266 | ✅ | ✅ | ✅ | ✅ |
| Arduino Mega/Uno | ❌ | ✅ | ❌ | ❌ |
| Arduino SAMD | ✅ | ✅ | ✅ | ✅ |
| STM32 | ❌ | ✅ | ✅ | ✅ |
| Raspberry Pi Pico (RP2040) | ✅ | ✅ | ✅ | ✅ |
⚠️ IMPORTANTE - Arduino Mega/Uno e SSL/TLS:Arduino Mega and Uno DO NOT support SSL/TLS due to severe RAM limitations:
- Arduino Mega has only 8KB of RAM
- Arduino Uno has only 2KB of RAM
- BearSSL for SSL/TLS requires at least 24KB of RAM for encryption buffers
Alternative solutions for Arduino Mega/Uno:
- ✅ Use non-secure SMTP (port 25) - Works but not recommended
- ✅ Use a local SMTP relay - Configure a local server that handles SSL
- ✅ Switch to ESP32/ESP8266 - They have more RAM and native SSL/TLS support
- ✅ Use Arduino SAMD (MKR WiFi 1010) - Has 32KB RAM and supports SSL/TLS
Arduino Mega/Uno examples in this library use only non-secure SMTP!
- WiFi (ESP32/ESP8266) - WiFiClient / WiFiClientSecure
- WiFi (SAMD/MBED) - WiFiNINA library
- Ethernet W5100/W5200/W5500 - Standard Ethernet library
- Ethernet ENC28J60 - UIPEthernet library
- Ethernet with SSL - SSLClient wrapper for secure connections
- SPIFFS (ESP32, ESP8266)
- LittleFS (ESP32, ESP8266, RP2040)
- FFAT (ESP32)
- SPIFM (SPI Flash with Adafruit_SPIFlash)
- Generic stream and string attachments option
- SD (Standard SD library)
- SdFat (Version 1.x for RP2040/ESP8266)
- SdFat2 (Version 2.x for modern platforms)
- Open Arduino IDE
- Go to Sketch > Include Library > Manage Libraries
- Search for "EMailSender"
- Click Install
Add to your platformio.ini:
lib_deps =
xreef/EMailSender@^4.1.1- Download the library from GitHub
- Extract to Arduino libraries folder
- Restart Arduino IDE
#include <WiFi.h>
#include <EMailSender.h>
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
// Gmail SMTP configuration
EMailSender emailSend("[email protected]",
"your_app_password",
"[email protected]",
"Your Name",
"smtp.gmail.com",
587); // Port 587 for STARTTLS
void setup() {
Serial.begin(115200);
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi Connected!");
// Prepare email message
EMailSender::EMailMessage message;
message.subject = "Test Email";
message.message = "Hello from ESP32!";
// Send email
EMailSender::Response resp = emailSend.send("[email protected]", message);
Serial.println("Sending status: ");
Serial.println(resp.code);
Serial.println(resp.desc);
Serial.println(resp.status);
}
void loop() {
// Nothing here
}EMailSender::EMailMessage message;
message.subject = "HTML Email Test";
message.message = "<h1>Hello!</h1><p>This is an <b>HTML</b> email.</p>";
message.mime = MIME_TEXT_HTML; // Set MIME type to HTML
// Multiple recipients
const char* recipients[] = {
"[email protected]",
"[email protected]",
"[email protected]"
};
EMailSender::Response resp = emailSend.send(recipients, 3, message);// Array with To, Cc, and Bcc addresses
const char* allRecipients[] = {
"[email protected]", // To (1)
"[email protected]", // Cc (1)
"[email protected]" // Bcc (1)
};
// send(recipients, numTo, numCc, numBcc, message)
EMailSender::Response resp = emailSend.send(allRecipients, 1, 1, 1, message);Enable debugging by uncommenting in EMailSenderKey.h:
#define EMAIL_SENDER_DEBUG
#define DEBUG_PRINTER SerialThis will print detailed SMTP communication to Serial Monitor.
For boards with limited RAM (like Arduino Uno):
- Disable attachments if not needed
- Use smaller email messages
- Consider using Arduino Mega or ESP32
"Username and Password not accepted"
- Enable 2-Factor Authentication
- Generate App Password at https://myaccount.google.com/apppasswords
- Use the 16-character app password (no spaces)
"Less secure app access"
- Google removed "less secure apps" option
- You MUST use App Passwords now
- Regular account password will not work
- 10/11/2025: v4.1.1
- Minor enhancements: add support for Stream and String attachments improvements
- Bug fixes: edge-case encoding issues and small fixes in attachment handling
- 10/11/2025: v4.1.0
- Add Stream and File as attachement type
- Bug fix for size and encoding
- 09/10/2025: v4.0.1 Fix path sslclient and code completition of Platformio
- ✨ STARTTLS support (Port 587) - Full implementation for secure email on port 587
- ✨ Internal SSLClient integration - Built-in SSL/TLS support for ESP32/ESP8266
- ✨ Enhanced authentication - Better support for various SMTP auth methods
- ✨ Improved error handling - More detailed error messages and responses
- 🔧 Unified client handling for better compatibility
- 🔧 Better SSL/TLS handshake management
- 🔧 Improved EHLO/HELO command handling with multi-line response support
- 🔧 Enhanced connection retry logic
- 🔧 Better memory management for large attachments
- 🐛 Fixed SSLClient initialization on ESP32
- 🐛 Fixed STARTTLS upgrade sequence
- 🐛 Corrected client scope issues
- 🐛 Fixed BearSSL integration for Ethernet shields
⚠️ Minimum Arduino IDE version: 1.8.x⚠️ ESP32 core minimum version: 2.0.x (for WiFiClientSecure improvements)⚠️ Some internal API changes (user-facing API remains compatible)
Most code will work without changes. If using custom client configuration:
- Check
EMailSenderKey.hfor new defines - Update authentication methods if using advanced features
- Test STARTTLS connections (port 587) for better security
- 14/03/2024: v3.0.14 Support Arduino GIGA WiFi
- 31/10/2023: v3.0.13 Fix wrong implementation of FORCE_DISABLE_SSL
- 17/10/2023: v3.0.12 Fix warnigs of variable not used #43 thanks to @Patriboom @Andy2015
- 16/02/2023: v3.0.11 Add support for Ethernet_Generic
- 20/01/2023: v3.0.10 Add the management of ESP8266SdFat library on Raspberry Pi Pico #forum
- 17/01/2023: v3.0.10 Add the mamagement of auto check of response number #36 thanks to @HACKER-3000 @H3
- 13/01/2023: v3.0.9 Fix external storage error 404 (#forum
- 05/01/2023: v3.0.8 Fix distribution list examples
- 22/09/2022: v3.0.7 Add Raspberry Pi Pico W and rp2040 boards
- 20/09/2022: v3.0.7 Add STM32 management for https://github.com/rogerclarkmelbourne/Arduino_STM32 library.
- 16/08/2022: v3.0.6 Add FORCE_DISABLE_SSL to disable SSL if present
- 19/07/2022: v3.0.5 Additional fix on additional response management (#26)
- 12/07/2022: v3.0.4 Fixed attachment issue on SPIFFS and LittleFS
- 06/07/2022: v3.0.3 Manage multiple response message after connect and HELO (#26)
- 03/06/2022: v3.0.2 Add possibility to set additionalResponseLineOnConnection with void setAdditionalResponseLineOnConnection(uint8_t numLines = 0), needed if on connection you receive 220 response as error, and add Ethernet2.
- 20/05/2022: v3.0.1 Put inside scope the client declaration (if you don't use SSLClient) for backward compatibility
- 18/05/2022: v3.0.0 Add STM32 support. Add SSLClient integration to allow send Email with SSL encryption (like Gmail) with ethernet (tested with STM32, ESP32, w5500, and enc28j60), minor fix
- 12/04/2021: v2.4.3 Fix multiple email send
- 12/04/2021: v2.4.1 Add support for LITTLEFS and Ffat on esp32 and fix certificate verification from esp32 core 1.0.5
- 18/03/2021: v2.3.0 Add support for LittleFS on esp8266
- 02/01/2021: v2.2.0 New support for SAMD devices via WiFiNINA (Arduino MKR WiFi 1010, Arduino Vidor 4000 and Arduino UNO WiFi Rev.2 ecc.).
- 01/01/2021: v2.1.5 Add possibility to use EHLO instead of HELO, and SASL login.
- 27/11/2020: v2.1.4 Add more constructor to allow more structure for distribution list (now const char*, char* and String array are supported)
MIT License - See LICENSE file for details
Copyright (c) 2017-2025 Renzo Mischianti
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
- Website: https://www.mischianti.org
- GitHub Issues: https://github.com/xreef/EMailSender/issues
- Forum: https://www.mischianti.org/forums/
Renzo Mischianti
- Website: https://www.mischianti.org
- Email: [email protected]
- GitHub: @xreef
If this library helped your project, please ⭐ star it on GitHub!
Made with ❤️ by Renzo Mischianti
