Learn how to send emails with the ESP32 using an SMTP Server. We’ll show you how to send a simple email with HTML or raw text and how to send attachments like images and files (.txt). The ESP32 board will be programmed using Arduino IDE.

You may also like reading: ESP32 / ESP8266 Send Email Notification using PHP Script
Introducing SMTP Servers
SMTP means Simple Mail Transfer Protocol and it is an internet standard for email transmission. To send emails using an ESP32, you need to connect it to an SMTP Server.
ESP32 MailClient Library
To send emails with the ESP32, we’ll use the ESP32 MailClient library. This library allows the ESP32 to send and receive emails with or without attachment via SMTP and IMAP servers.
In this tutorial we’ll use SMTP to send an email with and without attachments. As an example, we’ll send an image (.jpg) and a text (.txt) file. The files to be sent via email can be saved in the ESP32 SPIFFS or SD card.
Installing the ESP32 MailClient Library
Before proceeding with this tutorial, you need to install the ESP32 MailClient library. This library can be installed through the Arduino IDE Library Manager.
In your Arduino IDE go to Sketch > Include Library > Manage Libraries…
The Library Manager should open. Search for ESP32 Mail Client by Mobizt and install the library as shown below.

Sender Email (New Account)
We recommend creating a new email account to send the emails to your main personal email address. Do not use your main personal email to send emails via ESP32. If something goes wrong in your code or if by mistake you make too many requests, you can be banned or have your account temporary disabled.
We’ll use a newly created Gmail.com account to send the emails, but you can use any other email provider. The receiver email can be your personal email without any problem.
Create a Sender Email Account
Create a new email account for sending emails with the ESP32. If you want to use a Gmail account, go to this link to create a new one.

Allow less secure apps
Allow less secure apps to get access to this new Gmail account, so that you’re able to send emails. You can open this link to go to that menu.

Gmail SMTP Server Settings
If you’re using a Gmail account, these are the SMTP Server details:
- SMTP Server: smtp.gmail.com
- SMTP username: Complete Gmail address
- SMTP password: Your Gmail password
- SMTP port (TLS): 587
- SMTP port (SSL): 465
- SMTP TLS/SSL required: yes
Outlook SMTP Server Settings
For Outlook accounts, these are the SMTP Server settings:
- SMTP Server: smtp.office365.com
- SMTP Username: Complete Outlook email address
- SMTP Password: Your Outlook password
- SMTP Port: 587
- SMTP TLS/SSL Required: Yes
Live or Hotmail SMTP Server Settings
For Live or Hotmail accounts, these are the SMTP Server settings:
- SMTP Server: smtp.live.com
- SMTP Username: Complete Live/Hotmail email address
- SMTP Password: Your Windows Live Hotmail password
- SMTP Port: 587
- SMTP TLS/SSL Required: Yes
If you’re using another email provider, you need to search for its SMTP Server settings. Now, you have everything ready to start sending emails with your ESP32.
Send an Email with HTML or Raw Text with ESP32 (Arduino IDE)
The following code sends an email via SMTP Server with HTML or raw text. For demonstration purposes, the ESP32 sends an email once when it boots. Then, you should be able to modify the code and integrate it in your own projects.
Don’t upload the code yet, you need to make some modifications to make it work for you.
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp32-send-email-smtp-server-arduino-ide/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include "ESP32_MailClient.h"
// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";
// To send Email using Gmail use port 465 (SSL) and SMTP Server smtp.gmail.com
// YOU MUST ENABLE less secure app option https://myaccount.google.com/lesssecureapps?pli=1
#define emailSenderAccount "[email protected]"
#define emailSenderPassword "YOUR_EXAMPLE_EMAIL_PASSWORD"
#define emailRecipient "[email protected]"
#define smtpServer "smtp.gmail.com"
#define smtpServerPort 465
#define emailSubject "ESP32 Test"
// The Email Sending data object contains config and data to send
SMTPData smtpData;
// Callback function to get the Email sending status
void sendCallback(SendStatus info);
void setup(){
Serial.begin(115200);
Serial.println();
Serial.print("Connecting");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(200);
}
Serial.println();
Serial.println("WiFi connected.");
Serial.println();
Serial.println("Preparing to send email");
Serial.println();
// Set the SMTP Server Email host, port, account and password
smtpData.setLogin(smtpServer, smtpServerPort, emailSenderAccount, emailSenderPassword);
// For library version 1.2.0 and later which STARTTLS protocol was supported,the STARTTLS will be
// enabled automatically when port 587 was used, or enable it manually using setSTARTTLS function.
//smtpData.setSTARTTLS(true);
// Set the sender name and Email
smtpData.setSender("ESP32", emailSenderAccount);
// Set Email priority or importance High, Normal, Low or 1 to 5 (1 is highest)
smtpData.setPriority("High");
// Set the subject
smtpData.setSubject(emailSubject);
// Set the message with HTML format
smtpData.setMessage("<div style=\"color:#2f4468;\"><h1>Hello World!</h1><p>- Sent from ESP32 board</p></div>", true);
// Set the email message in text format (raw)
//smtpData.setMessage("Hello World! - Sent from ESP32 board", false);
// Add recipients, you can add more than one recipient
smtpData.addRecipient(emailRecipient);
//smtpData.addRecipient("[email protected]");
smtpData.setSendCallback(sendCallback);
//Start sending Email, can be set callback function to track the status
if (!MailClient.sendMail(smtpData))
Serial.println("Error sending Email, " + MailClient.smtpErrorReason());
//Clear all data from Email object to free memory
smtpData.empty();
}
void loop() {
}
// Callback function to get the Email sending status
void sendCallback(SendStatus msg) {
// Print the current status
Serial.println(msg.info());
// Do something when complete
if (msg.success()) {
Serial.println("----------------");
}
}
You need to insert your network credentials as well as setting the sender email, SMTP Server details, recipient and message.
How the Code Works
Include the ESP32_MailClient.h library.
#include "ESP32_MailClient.h"
Network credentials
Insert your network credentials in the following variables, so that the ESP32 is able to connect to the internet to send the emails.
// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = "RAPLACE_WITH_YOUR_SSID";
const char* password = "RAPLACE_WITH_YOUR_PASSWORD";
Email settings
Insert the email sender account on the emailSenderAccount variable and its password on the emailSenderPassword variable.
#define emailSenderAccount "[email protected]"
#define emailSenderPassword "email_sender_password"
Insert the recipient email. This is the email that will receive the emails sent by the ESP32:
#define emailRecipient "[email protected]"
Insert your email provider SMTP settings on the following lines (we’re using the settings for a Gmail account):
#define smtpServer "smtp.gmail.com"
#define smtpServerPort 465
Write the email subject on the emailSubject variable.
#define emailSubject "ESP32 Test"
Create an STMPData object called smtpData that contains the data to send via email and all the other configurations.
SMTPData smtpData;
setup()
In the setup(), connect the ESP32 to Wi-Fi.
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(200);
}
The following line sets the SMTP Server host, SMTP port, account email address and password used to login:
smtpData.setLogin(smtpServer, smtpServerPort, emailSenderAccount, emailSenderPassword);
Set the sender name and sender email. In this case, we’re setting the sender name to ESP32.
smtpData.setSender("ESP32", emailSenderAccount);
Set the email priority.
smtpData.setPriority("High");
Set the email subject.
smtpData.setSubject(emailSubject);
The following line sets the message. You can send an HTML text or raw text. In this case, we’re sending a message with some HTML.
smtpData.setMessage("<div style=\"color:#2f4468;\"><h1>Hello World!</h1><p>- Sent from ESP32 board</p></div>", true);
When sending a message in HTML format, you should pass true as a second parameter to the setMessage() method. If you want to send raw text, set false.
//smtpData.setMessage("Hello World! - Sent from ESP32 board", false);
Finally, set the recipient email. This is the email that will receive the messages from the ESP32.
smtpData.addRecipient(emailRecipient);
Now that we’ve set all the details of the smtpData, we’re ready to send the email.
if (!MailClient.sendMail(smtpData))
Serial.println("Error sending Email, " + MailClient.smtpErrorReason());
After sending the email, you can clear all the data from the smtpData object.
smtpData.empty();
In this example, the email is sent once when the ESP32 boots, that’s why the loop() is empty.
void loop() {
}
Demonstration
Upload the code to your ESP32. After uploading, open the Serial Monitor at a baud rate of 115200. Press the ESP32 Reset button.
If everything went as expected you should get a similar message in the Serial Monitor.

Check your email account. You should have received an email from your ESP32 board.

If you set the option to send a message with HTML text, this is how the message looks like:

If you’ve enable the raw text message, this is the email that you should receive.

Send Attachments via Email with ESP32 (Arduino IDE)
In this section, we’ll show you how to send attachments in your emails sent by the ESP32. We’ll show how to send .txt files or pictures. This can be useful to send a .txt file with sensor readings from the past few hours, or to send a photo captured by an ESP32-CAM.
The files to be sent should be saved on the ESP32 SPIFFS or in a microSD card. In this example, we’ll be using SPIFFS (but the code provided can be changed to use a microSD card).
Upload files to SPIFFS
To send files via email, these should be saved on the ESP32 SPIFFS, or in a microSD card. We’ll upload a picture and a .txt file to the ESP32 SPIFFS using the ESP32 Filesystem Uploader plugin for Arduino IDE. Follow the next tutorial to install the plugin if you don’t have it installed yet:
Create a new Arduino sketch and save it. Go to Sketch > Show Sketch folder. Inside the Arduino sketch folder, create a folder called data. Move a jpg file and .txt file to your data folder.
Alternatively, you can click here to download the project folder.
Note: with the default code your files must be named ESP32-CAM-Test.jpg and text_file.txt or you can modify the code to import files with a different name.
We’ll be sending these files:

Your folder structure should look as follows (download project folder):

After moving the files to the data folder, in your Arduino IDE, go to Tools > ESP32 Data Sketch Upload and wait for the files to be uploaded.

You should get a success message on the debugging window. If the files were successfully uploaded, move on to the next section.

Note: if you start seeing many dots ….____…..____ being printed on the debugging window, you need to hold the ESP32 on-board BOOT button for the files to be uploaded.
Code
The following code sends an email with a .txt file and a picture attached. Before uploading the code, make sure you insert your sender emails settings as well as your recipient email.
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp32-send-email-smtp-server-arduino-ide/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include "ESP32_MailClient.h"
#include "SD.h"
#include "SPIFFS.h"
// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";
// To send Email using Gmail use port 465 (SSL) and SMTP Server smtp.gmail.com
// YOU MUST ENABLE less secure app option https://myaccount.google.com/lesssecureapps?pli=1
#define emailSenderAccount "[email protected]"
#define emailSenderPassword "YOUR_EXAMPLE_EMAIL_PASSWORD"
#define emailRecipient "[email protected]"
#define smtpServer "smtp.gmail.com"
#define smtpServerPort 465
#define emailSubject "ESP32 Test Email with Attachments"
// The Email Sending data object contains config and data to send
SMTPData smtpData;
// Callback function to get the Email sending status
void sendCallback(SendStatus info);
void setup(){
Serial.begin(115200);
Serial.println();
// Initialize SPIFFS
if(!SPIFFS.begin(true)) {
Serial.println("An Error has occurred while mounting SPIFFS");
return;
}
// Or initialize SD Card (comment the preceding SPIFFS begin)
/*
MailClient.sdBegin(14, 2, 15, 13); // (SCK, MISO, MOSI, SS)
if(!SD.begin()){
Serial.println("Card Mount Failed");
return "";
}*/
Serial.print("Connecting");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(200);
}
Serial.println();
Serial.println("WiFi connected.");
Serial.println();
Serial.println("Preparing to send email");
Serial.println();
// Set the SMTP Server Email host, port, account and password
smtpData.setLogin(smtpServer, smtpServerPort, emailSenderAccount, emailSenderPassword);
// For library version 1.2.0 and later which STARTTLS protocol was supported,the STARTTLS will be
// enabled automatically when port 587 was used, or enable it manually using setSTARTTLS function.
//smtpData.setSTARTTLS(true);
// Set the sender name and Email
smtpData.setSender("ESP32", emailSenderAccount);
// Set Email priority or importance High, Normal, Low or 1 to 5 (1 is highest)
smtpData.setPriority("High");
// Set the subject
smtpData.setSubject(emailSubject);
// Set the message with HTML format
smtpData.setMessage("<div style=\"color:#2f4468;\"><h1>Hello World!</h1><p>- Sent from ESP32 board</p></div>", true);
// Set the email message in text format (raw)
//smtpData.setMessage("Hello World! - Sent from ESP32 board", false);
// Add recipients, you can add more than one recipient
smtpData.addRecipient(emailRecipient);
//smtpData.addRecipient("[email protected]");
// Add attach files from SD card or SPIFFS
// Comment the next two lines, if no SPIFFS files created or SD card connected
smtpData.addAttachFile("/ESP32-CAM-Test.jpg", "image/jpg");
smtpData.addAttachFile("/text_file.txt");
// Add some custom header to message
// See https://tools.ietf.org/html/rfc822
// These header fields can be read from raw or source of message when it received)
//smtpData.addCustomMessageHeader("Date: Sat, 10 Aug 2019 21:39:56 -0700 (PDT)");
// Be careful when set Message-ID, it should be unique, otherwise message will not store
//smtpData.addCustomMessageHeader("Message-ID: <[email protected]>");
// Set the storage type to attach files in your email (SPIFFS or SD Card)
smtpData.setFileStorageType(MailClientStorageType::SPIFFS);
//smtpData.setFileStorageType(MailClientStorageType::SD);
smtpData.setSendCallback(sendCallback);
//Start sending Email, can be set callback function to track the status
if (!MailClient.sendMail(smtpData))
Serial.println("Error sending Email, " + MailClient.smtpErrorReason());
//Clear all data from Email object to free memory
smtpData.empty();
}
void loop() {
}
// Callback function to get the Email sending status
void sendCallback(SendStatus msg) {
// Print the current status
Serial.println(msg.info());
// Do something when complete
if (msg.success()) {
Serial.println("----------------");
}
}
How the code works
This code is very similar to the previous one, so we’ll just take a look at the relevant parts to send attachments.
In the setup(), you need to initialize SPIFFS:
if(!SPIFFS.begin(true)) {
Serial.println("An Error has occurred while mounting SPIFFS");
return;
}
If you want to send files saved on the microSD card, uncomment the next lines (make sure you insert the right pin assignment for the microSD card):
/*
MailClient.sdBegin(14, 2, 15, 13); // (SCK, MISO, MOSI, SS)
if(!SD.begin()){
Serial.println("Card Mount Failed");
return "";
}*/
Then, to attach a file, you just need to call the addAtatachFile() on the smtpData object and pass as argument the file path. For example, the image we’ll send is called ESP32-CAM-Test.jpg, so, send it as follows:
smtpData.addAttachFile("/ESP32-CAM-Test.jpg", "image/jpg");
The text file we want to send is called text_file.txt:
smtpData.addAttachFile("/text_file.txt");
If you want to send different files, you just need to change the path.
Finally, you need to set where your files are saved (SPIFFS or SD card). We’re using SPIFFS:
smtpData.setFileStorageType(MailClientStorageType::SPIFFS);
If you want to use SD card, comment the previous line and uncomment the following:
//smtpData.setFileStorageType(MailClientStorageType::SD);
And that’s it! As you can see the code to send an attachment via email is very simple.
Demonstration
After uploading the code, open the Serial Monitor at a baud rate of 115200 and press the on-board EN/RESET button. If everything goes smoothly, you should get a similar message on the Serial Monitor.

Check the recipient’s email address. You should have a new email with two attachments.

Wrapping Up
In this tutorial you’ve learned how to send emails with the ESP32 using an SMTP Server. For this method to work, the ESP32 should have access to the internet.
If you don’t want to use an SMTP Server, you can also write a PHP script to send email notifications with the ESP32 or ESP8266 board.
You’ve learned how to send a simple email with text and with attachments. When using attachments, these should be save on an SD card or on SPIFFS.
The examples presented show how to send a single email when the ESP32 boots. The idea is to modify the code and include it in your own projects. For example, it can be useful to send a .txt file with the sensor readings, to send a photo captured with the ESP32-CAM, use deep sleep to wake up your board every hour and send an email with data, etc.
We hope you’ve find this tutorial interesting.
To learn more about the ESP32, take a look at our resources:
Thanks for reading.
Dear Rui and Sara
Excellent work, this makes me very happy!
Thanks a lot
Best Regards
You’re welcome!
When I run the program, this message appeared
SPIFFS Not Supported on avr
Did you select the ESP32 board? Does your code still compile and upload? Sometimes you’ll see those warning messages and you can ignore them
Hello,
I would like to thank you for your tutorials.
I tried to send email with a wemos D1 mini using the code in this blog and I got the following error:
/home/samorai/Arduino/libraries/ESP32_Mail_Client/src/ssl_client32.h:32:30: fatal error: mbedtls/platform.h: No such file or directory
#include “mbedtls/platform.h”
I am using the latest IDE version.
Any idea how to solve this?
Thanks and regards
Hello,
This issue was solved by downloading https://tls.mbed.org/download/start/mbedtls-2.16.4-apache.tgz and including it in /home/samorai/Arduino/libraries/ESP32_Mail_Client folder.
Regards
Great!
Thanks for sharing that.
Regards,
Sara
Howdy,
I’ve included this file into my ESP32_Mail_Client folder and still receive the same error when compiling. Does anyone have any solutions?
Thanks
I’ve got the code in my Arduino IDE, but cannot compile. I am seeing the same error.
When I include this folder in src > mbedtls the includes seem to work, but now I have illicited this response from the code. >…/ESP32_Mail_Client/src/ESP32_MailClient.h:37:18: fatal error: ETH.h: No such file or directory
>#include “ETH.h”
I’m going to keep chasing this, but I feel like I have some library mismatch or version wrong. Any insights?
Working with an 8266 – and just realizing as I typed it out that may be the source of my trouble.
Hi Zach.
Unfortunately, this project is not compatible with the ESP8266.
Regards,
Sara
Another top class tutorial from RNT ! Kudos.
I was looking for this exact tutorial for a long time and you guys did it. Worked first shot … both the HTML and Text version mails.
Great. Now I can get a mail when my UPS battery needs charging or when my sump water level drops below the danger mark or …. the list is endless.
That’s great!
I’m glad you found it useful.
Regards,
Sara 😀
Was getting many compilation until I installed version 1.0.4 for ESP32.
Now the first text example works, will try the rest soon,
Thanks!
Compilation errors, I meant.
If you got this obscure error below,
#error: architecture or board not supported
It has to do with the
#include “ESP32_MailClient.h”
is calling an old SD card library,
When I got this error, the compiler is using a very old library that doesn’t recognize ESP32. I removed all the old libraries until the compiler is using the ESP32 SD card library – see below.
Using library SD at version 1.0.5 in folder: C:\Users\one\Documents\Arduino\hardware\esp32\arduino-esp32-master\libraries\SD
Hope this helps!
Hi.
Thanks for sharing that.
I will be helpful for our readers.
Regards,
Sara
I have been looking for exactly this! Just great you posted it.
I have the recommended ESP32 board, but the compiler tells me: “”Error compiling for board DOIT ESP32 DEVKIT V1”. Could you please help me out? Any pointers?
I think A Lee had the same issue, and … the fix. I would like to try it. How do I remove and old library? I know …. rookie question.
When you get the error, what part of the code gets highlighted?
That indicates where the error is.
Regards,
Sara
Thank you for your quick response. In the meantime I have completely removed the entire Arduino installation and its libraries and reinstalled a clean version. It compiles! 🙂
If you go to File Preference and click Show Verbose Output during compilation. Then you will see a lot of messages on the screen. After the compiler stopped, you would see this message on the screen in red.
exit status 1
Error compiling for board ESP32 Dev Module.
Scroll up and see where is error comes from.
C:\Users\One\Documents\Arduino\libraries\SD\src/utility/Sd2PinMap.h:524:2: error: #error Architecture or board not supported.
#error Architecture or board not supported.
^
Sd2PinMap.h is a file under the SD directory. My Google search found not much with this type of error. One poster said the library doesn’t suppose the lastest board. It means sense because the error is Architecture or board not supported.
I figured – the SD library probably is “old”. I started moving it to another drive in my PC and recompile the sketch. Below is the compiler telling which library it was using to compile the sketch.
Multiple libraries were found for “SD.h”
Used: C:\Users\One\Documents\Arduino\libraries\SD
Not used: C:\Users\One\Documents\Arduino\hardware\esp32\arduino-esp32-master\libraries\SD
I moved the SD directory that it was using to another drive.
Then it complied with no error. I scroll up the screen and saw it was using the esp32 library.
Using library SD at version 1.0.5 in folder: C:\Users\One\Documents\Arduino\hardware\esp32\arduino-esp32-master\libraries\SD
It works for me. Good luck!
Thank you A Lee for your extensive response!
Hello, thank you for this tutorial. I am getting the following error message. Your thoughts, please. Thanks, Mac
Connecting to SMTP server…
SMTP server connected, wait for response…
Identification…
Authentication…
Sign in…
Error, login password is not valid
Error sending Email, login password is not valid
Hi.
That means that the password you’ve inserted is not correct for the sender email.
Regards,
Sara
I have the same issue.
I just made the email account, so I know it’s the right PW.
Does it have issue with the ‘#’ symbol?
Andy
Hi Andy.
Double-check that you have access to less secure apps enable.
Sometimes Gmail changes that option without our permission.
Regards,
Sara
Triple checked.
I even set up a new Outlook account to see if it was Gmail.
I get the same error.
Should I try another email?
Andy
Hi Andy.
Honestly, I don’t know.
It worked fine for me using a Gmail account.
If you change to another email provider, check that you have the right smtp settings for that email provier.
Regards,
Sara
Hi,
you should turn on Allow less secure apps on Gmail. This will solve your problem.
Hello Macin,
I get the same issue but not always. Issue does not come from my password or Id because sometimes it works ! did you find a solution to your issue ?
I’ve had the same issue, though the password was correct. I’ve done the following and it now works well:
– Enable less secure apps
– Enable 2-Step verification
– Then Manage your google account>Security>Sign in to Google>App password>create a new app password which can only be used in the device you choose.
The generated password should be placed on the arduino sketch replacing your main accounts password.
If you have several ESP32 (or other devices) you should generate an app password per device.
Hope this helps.
Hello, First of all, thanks for this post.
I want to send an email when my Magnetic switch is HIGH. Magnetic Switch is connected to ESP32. So in which part of the code I should add this?
It might be a simple question but I am new in Arduino, and ESP32, so please help me.
Hello and well done for your work.
I am new to the subject and I don’t know what “SSID” is or where to find it.
Thank you for informing me.
Regards
Hi Jean.
SSID is the name of your internet network (Wi-Fi).
Usually, there’s a sticker below the router with the wi-fi name.
Also, if you search for Wi-Fi networks with your smartphone, you’ll find its name.
Regards,
Sara
Thank you for your reply Sara.
Regards.
Hi all, is there a library like “ESP32_MailClient.h” for ESP8266?
Or how can I use this code for ESP8…
Hi Tom.
This code is not compatible with ESP8266.
You can use this library to send emails with ESP8266: https://github.com/xreef/EMailSender
Regards,
Sara
dear if I want to send voltage value , what I should do since smtpData.setMessage(“ALI SHAMI testing “, false); support only char . thxx in advance
Hi.
You can take a look at this project that sends temperature values via email. Instead of temperature values, you can send voltage.
https://randomnerdtutorials.com/esp32-email-alert-temperature-threshold/
You need something as follows, for example:
String emailMessage = String(“Testing: “) + String(voltage)
Then, use:
smtpData.setMessage(emailMessage, true);
I hope this helps.
Regards,
Sara
Hello, thank you very much for the publications, you are great.
I have finished your project and I receive the email without the files, this is what I see on the serial monitor:
Connecting
WiFi connected.
Preparing to send email
Connecting to SMTP server …
SMTP server connected, wait for response …
Identification …
Authentication …
Sign in …
Sending Email header …
Sending Email body …
Sending attachments …
Finish …
Finished
Email sent successfully
—————-
however in the “data” folder are your files. Sorry if it’s a silly question but I’m a newbie.😊
Hi Rafa.
Thanks for your question. Did you upload the files to the ESP32 SPIFFS?
After moving the files to the data folder, you need to go to Tools > ESP32 Data Sketch Upload
Regards,
Sara
Thanks for your response and sorry for the delay. It is possible that this is the problem, I have several Arduino installations and maybe it confused me. Thank you
Hi Rafa.
Use only one Arduino installation to avoid problems and conflicts with libraries.
Regards,
Sara
Dear Rui and Sara
I thank U for your Excellent work,
I have a liiiitle problem with the attached file: it is on the SD card and I the error is in this lines :
MailClient.sdBegin(18, 19, 23, 5); // (SCK, MISO, MOSI, CS)
if(!SD.begin()){
Serial.println(“Card Mount Failed”);
return “”;
}
the error is : exit status 1
return-statement with a value, in function returning ‘void’ [-fpermissive]
I beg your help, superplease!
Simplemente borra las comillas es un error de tecleado.
Hi Rui and Sara,
It is awesome…thank you so much. Works as expected at first try with Gmail account.
Best regards,
Tondium
Great! 🙂
Hi,
when I compile the sketch send email on a ESP32 dev board, I get several compiler errors. Which library is missing?
Here the errors:
/Users/myName/Documents/Arduino/hardware/espressif/esp32/libraries/ESP32-Mail-Client/src/ssl_client32.cpp: In function ‘int start_ssl_client(sslclient_context32*, const char*, uint32_t, int, const char*, const char*, const char*, const char*, const char)’:
/Users/myName/Documents/Arduino/hardware/espressif/esp32/libraries/ESP32-Mail-Client/src/ssl_client32.cpp:101:48: error: cannot call member function ‘int WiFiGenericClass::hostByName(const char, IPAddress&)’ without object
if (!WiFiGenericClass::hostByName(host, srv))
^
/Users/myName/Documents/Arduino/hardware/espressif/esp32/libraries/ESP32-Mail-Client/src/ssl_client32.cpp:271:85: error: ‘mbedtls_ssl_conf_psk’ was not declared in this scope
(const unsigned char *)pskIdent, strlen(pskIdent));
^
/Users/myName/Documents/Arduino/hardware/espressif/esp32/libraries/ESP32-Mail-Client/src/ESP32_MailClient.cpp: In member function ‘bool ESP32_MailClient::waitIMAPResponse(IMAPData&, uint8_t, int, int, int, std::__cxx11::string)’:
/Users/myName/Documents/Arduino/hardware/espressif/esp32/libraries/ESP32-Mail-Client/src/ESP32_MailClient.cpp:2460:9: error: ‘transform’ is not a member of ‘std’
std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
^
/Users/myName/Documents/Arduino/hardware/espressif/esp32/libraries/ESP32-Mail-Client/src/ESP32_MailClient.cpp:2629:13: error: ‘sort’ is not a member of ‘std’
std::sort(imapData._msgNum.begin(), imapData._msgNum.end(), compFunc);
^
/Users/myName/Documents/Arduino/hardware/espressif/esp32/libraries/ESP32-Mail-Client/src/ESP32_MailClient.cpp: In member function ‘void IMAPData::setFetchUID(const String&)’:
/Users/myName/Documents/Arduino/hardware/espressif/esp32/libraries/ESP32-Mail-Client/src/ESP32_MailClient.cpp:3702:3: error: ‘transform’ is not a member of ‘std’
std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::toupper);
^
Is there still a chance that I get an answer to my question? Thanks!
Hi Kurt.
I’m sorry for taking so long to see your comment.
I think you have some problem with the library.
I suggest that you delete the library from the libraries folder and try to install it again.
Regards,
Sara
Love this project, easy to follow and understand. Works great until I use a battery to power the ESP32. I tried different cables,batteries, power supply with no success in sending. Nothing happens. Plugged it into a wall jack with the 5v adapter and it works fine.
What am I missing.
Hi Karel.
What battery are you using to power the ESP32?
You can take a look at this project (ignore the solar panels, just take a look at the battery side): https://randomnerdtutorials.com/power-esp32-esp8266-solar-panels-battery-level-monitoring/
Regards,
Sara
Hi Sara
I’m using a 9V with the ardunio power board and have also tried the LM317 regulator set to 5v. No go. As soon as I switch to the micro usb email arrives no problem.???
I’m at a loss?
hello,
can you set this project to work that
door status monitor
made by you? because that project doesnt work anymore because of IFTTT upgrade….thanks
The code works great, my question is how to add multiple recipients for a message.
Hi Guys!
I was trying to send a sensor value (MQ-2) by e-mail, using the Wemos Lolin Oled and your code. But all the analog input PINs go to 100%… And I don’t know why!
Do you have some idea that is happening?
Best,
Ricardo
Sorry! Without the email code, I can see the sensor value on Oled display. But when the email code is added, the sensor value goes to 4095…
Hi Ricardo.
You’re probably using an ADC2 analog pin.
ADC2 doesn’t work well with Wi-Fi.
You must choose an ADC1 pin. See the ESP32 pinout guide here: https://randomnerdtutorials.com/esp32-pinout-reference-gpios/
Regards,
Sara
Thank you!
In fact, I’m using the Esp32 Oled board. But I connected the sensor to GPIO 36 (that’s an ADC1) and now the analogRead () is working.
Thanks again!
Ricardo
Is there any requirement of doing some connections with esp32.
Hi.
What do you mean?
Connections with sensors and outputs?
Take a look at this guide: https://randomnerdtutorials.com/esp32-pinout-reference-gpios/
Regards,
Sara
Thanks the Santos to provide a lot of good projects on this site. One of my struggles is to know what IP is assigned to a “webserver” by the wireless router if there is no “display” available to show the IP address. Below are the changes that I made to the test email sketch to make it possible.
Modify the emailSubject as a String; add localIP as a variable
String emailSubject;
IPAddress localIP;
Add the following at the end of the Setup
Serial.print(“IP: “);Serial.println(WiFi.localIP());
localIP = WiFi.localIP();
emailSubject =String( localIP[0]) + “.” + String( localIP[1])+ “.” + String( localIP[2]) + “.” + String( localIP[3]);
SMTPsendmail();
When you receive the email from your project, the IP address is on the Subject.
Have fun!
Rui and Sara, I’m here from BRasil to accompany you. Congratulations!
Which command do I use to delete the SPIFFS file after it is sent?
Hi.
You can use the following command:
SPIFFS.remove(“/filename”);
Replace filename with the name of the file you want to remove. You also need to include the file extension.
Regards,
Sara
What about new version ESP32_Mail_Client.h?
Is it necesary to change?
Thanks a lot
Hello, great article and this library is working very well ! Thanks.