Giter Site home page Giter Site logo

mobizt / esp-mail-client Goto Github PK

View Code? Open in Web Editor NEW
186.0 15.0 54.0 7.28 MB

The comprehensive Arduino Email Client Library to send and read Email for Arduino devices. The library also supports other network shields or modules e.g., Wi-Fi, Ethernet, and GSM/4G modules.

Home Page: https://mobizt.github.io/ESP-Mail-Client/

License: MIT License

C++ 18.96% C 81.04%
esp8266 esp32 arduino email sender smtp imap email-client arduino-library rfc822

esp-mail-client's Introduction

ESP Mail

Compile Examples Github Stars Github Issues

arduino-library-badge PlatformIO

The comprehensive Arduino Email Client Library to send and read Email for Arduino devices.

This library was tested and works well with ESP32s, ESP8266s, SAMD21s and RP2040 Pico based modules.

The library supported external networking devices hat work with Arduino Clients e.g. WiFiClient, EthernetClient, and GSMClient.

Minimum 200k flash space device is recommended for library installation and user code.

The minimum ram requirement is based on the applications (SMTP and IMAP). IMAP application may required up to 20k memory while SMTP application required much less memory.

Table of Contents

  1. Features
  2. Supported Devices
  3. Prerequisites
    1. Gmail SMTP and IMAP required App Passwords to sign in
    2. PlatformIO IDE Compile Options
    3. Third party SD library must be removed
    4. SdFat conflicts in ESP8266 and must be removed
    5. ESP32 and ESP8266 SDKs
    6. RP2040 Arduino SDK
  4. Library Instalation
    1. Using Library Manager
    2. Manual installation
  5. Memory Options
    1. Memory Options for ESP8266
    2. Arduino IDE
    3. PlatformIO IDE
    4. ESP8266 and SRAM/PSRAM Chip connection
    5. Memory Options for ESP32
    6. Arduino IDE
    7. PlatformIO IDE
  6. Library Build Options
    1. Predefined Options
    2. Optional Options
  7. Usage
    1. Send Email message
    2. Read Email message
    3. Get Incoming Message Notification and Reading
    4. Sending Custom IMAP commands
    5. Using TCP session KeepAlive in ESP8266 and ESP32
    6. Use external Arduino Clients interfaces
    7. TTGO T-A7670 LTE with TinyGSM
    8. ESP32 and W5500
  8. Acheivement
    1. Open Sourcs Contribution Awards
  9. Sponsors
  10. License

Features

  • Supports sending Email with attachments.
  • Supports reading the message and listening the mailbox changes.
  • Supports custom SMTP and IMAP commands.
  • Supports PLAIN, LOGIN and XOAUTH2 authentication mechanisms.
  • Supports standard ports and user defined ports.
  • Supports STARTTLS for both SMTP and IMAP.
  • Supports TCP session reusage.
  • Supports the content encodings e.g. quoted-printable and base64.
  • Supports the content decodings e.g. base64, UTF-8, UTF-7, quoted-printable, ISO-8859-1 (latin1) and ISO-8859-11 (Thai).
  • Supports embedded contents e.g. inline images, attachments, parallel media attachments and RFC822 message.
  • Supports IMAP MIME data stream callback for external reader.
  • supports IMAP custom character decoding callback based on the character set.
  • Support full debuging.
  • Support on-board or native networking (WiFi and Ethernet) and external networking (WiFi, Ethernet and GSM) via external basic WiFiClient, EthernetClient and GSMClient.
  • Supports TinyGSM library integration.

Supported Devices

This following devices are supported.

  • ESP8266 MCUs based boards
  • ESP32 MCUs based boards
  • Arduino MKR WiFi 1010
  • Arduino MKR 1000 WIFI
  • Arduino Nano 33 IoT
  • Arduino MKR Vidor 4000
  • Raspberry Pi Pico (RP2040)
  • Arduino UNO R4 WiFi (Renesas).
  • LAN8720 Ethernet PHY
  • TLK110 Ethernet PHY
  • IP101 Ethernet PHY
  • ENC28J60 SPI Ethernet module
  • W5100 SPI Ethernet module
  • W5500 SPI Ethernet module
  • SIMCom Modules with TinyGSMClient

Prerequisites

Gmail SMTP and IMAP required App Passwords to sign in

From May 30, 2022, Google no longer supports the use of third-party apps or devices which ask you to sign in to your GoogleAccount using only your username and password.

This means the Gmail account credentials i.e. account Email and account password can't be used to sign in with Google SMTP and IMAP servers. This prevents the third party apps hack to Gmail user account.

To use Gmail with this library, you need to use App Passwords instead.

For setting up the App Passwords, please read here.

After you created App Password, you can use Gmail Email address and App Password created to sign in as the following.

config.login.email = "<your email>";
config.login.password = "<your app password>";

PlatformIO IDE Compile Options

For Arduino Nano RP2040 Connect board, using PlatformIO IDE, to prevent the compile error due to wrong headers compilation, please set the lib_ldf_mode in platformio.ini as this.

lib_ldf_mode = chain+

Third party SD library must be removed

In Arduino IDE, all third party SD libraries installed in libraries folder must be reboved.

The Core SD library was used instead of third party SD libraries.

SdFat conflicts in ESP8266 and must be removed

The SdFat is already implemented as wrapper class in ESP8266 core library.

For Arduino IDE, the SdFat library should be removed from libraries folder when you compile this library for ESP8266 because of conclicts with core library SDFS.h.

ESP32 and ESP8266 SDKs

For Espressif's ESP32 and ESP8266 based boards, this library requires Arduino's ESP32 or ESP8266 Core SDK to be installed.

The latest Core SDK is recommended. For ESP8266, the Core SDK version 3.x.x or later is recommended.

The ESP8266 Core SDK version 2.5.x and earlier are not supported.

For ESP32, the Core SDK version 2.0.4 or later is recommended.

The ESP32 Core SDK version 1.0.4 and earlier are not supported.

RP2040 Arduino SDK

For Arduino IDE, the Arduino-Pico SDK can be installed from Boards Manager by searching pico and choose Raspberry Pi Pico/RP2040 to install.

For PlatformIO, the Arduino-Pico SDK can be installed via platformio.ini

[env:rpipicow]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = rpipicow
framework = arduino
board_build.core = earlephilhower
monitor_speed = 115200
board_build.filesystem_size = 1m

See this Arduino-Pico SDK documentation for more information.

Library Instalation

Using Library Manager

At Arduino IDE, go to menu Sketch -> Include Library -> Manage Libraries...

In Library Manager Window, search "ESP Mail Client" in the search form then select "ESP Mail Client".

Click "Install" button.

For PlatformIO IDE.

Go to PIO Home -> Libraries -> Registry then search ESP Mail Client.

If you ever installed this library in Global storage in PlatformIO version prior to v2.0.0 and you have updated the PlatformIO to v2.0.0 and later, the global library installation was not available, the sources files of old library version still be able to search by the library dependency finder (LDF), you needed to remove the library from folder C:\Users\<UserName>\.platformio\lib to prevent unexpected behavior when compile and run.

Manual installation

Click on Code dropdown at the top of repository, select Download ZIP and save file on your computer.

From Arduino IDE, goto menu Sketch -> Include Library -> Add .ZIP Library... and choose ESP-Mail-Client-master.zip that previously downloaded.

Rename ESP-Mail-Client-master folder to ESP_Mail_Client.

Go to menu Files -> Examples -> ESP Mail Client and choose one from examples

Memory Options

Memory Options for ESP8266

This section is optional for memory settings in IDE.

When you update the ESP8266 Arduino Core SDK to v3.0.0, the memory can be configurable from IDE.

You can choose the Heap memory between internal and external memory chip from IDE e.g. Arduino IDE and PlatformIO on VSCode or Atom IDE.

Arduino IDE

For ESP8266 devices that don't have external SRAM/PSRAM chip installed, choose the MMU option 3, 16KB cache + 48KB IRAM and 2nd Heap (shared).

Arduino IDE config

For ESP8266 devices that have external 23LC1024 SRAM chip installed, choose the MMU option 5, 128K External 23LC1024.

MMU VM 128K

For ESP8266 devices that have external ESP-PSRAM64 chip installed, choose the MMU option 6, 1M External 64 MBit PSRAM.

PlatformIO IDE

The MMU options can be selected from build_flags in your project's platformio.ini file

For ESP8266 devices that don't not have external SRAM/PSRAM chip installed, add build flag as below.

[env:d1_mini]
platform = espressif8266
build_flags = -D PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
board = d1_mini
framework = arduino
monitor_speed = 115200

For ESP8266 devices that have external 23LC1024 SRAM chip installed, add build flag as below.

[env:d1_mini]
platform = espressif8266
;128K External 23LC1024
build_flags = -D PIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_128K
board = d1_mini
framework = arduino
monitor_speed = 115200

For ESP8266 devices that have external ESP-PSRAM64 chip installed, add build flag as below.

[env:d1_mini]
platform = espressif8266
;1M External 64 MBit PSRAM
build_flags = -D PIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_1024K
board = d1_mini
framework = arduino
monitor_speed = 115200

ESP8266 and SRAM/PSRAM Chip connection

Most ESP8266 modules don't have the built-in SRAM/PSRAM on board. External memory chip connection can be done via SPI port as below.

23LC1024/ESP-PSRAM64                ESP8266

CS (Pin 1)                          GPIO15
SCK (Pin 6)                         GPIO14
MOSI (Pin 5)                        GPIO13
MISO (Pin 2)                        GPIO12
/HOLD (Pin 7 on 23LC1024 only)      3V3
Vcc (Pin 8)                         3V3
Vcc (Pin 4)                         GND

Once the external Heap memory was selected in IDE, to allow the library to use the external memory, you can set it in ESP_Mail_FS.h by define this macro.

#define ESP_MAIL_USE_PSRAM

This macro was defined by default when you installed or update the library.

Memory Options for ESP32

This section is optional for memory settings in IDE.

In ESP32 module that has PSRAM installed, you can enable it and set the library to use this external memory instead.

Arduino IDE

To enable PSRAM in ESP32 module.

Enable PSRAM in ESP32

PlatformIO IDE

In PlatformIO on VSCode or Atom IDE, add the following build_flags in your project's platformio.ini file.

build_flags = -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue

As in ESP8266, once the external Heap memory was enabled in IDE, to allow the library to use the external memory, you can set it in ESP_Mail_FS.h by define this macro.

#define ESP_MAIL_USE_PSRAM

Library Build Options

The library build options are defined as preprocessor macros (#define name).

Some options can be disabled to reduce program space.

Predefined Options

The predefined options that are already set in ESP_Mail_FS.h are following.

ENABLE_IMAP // For IMAP class compilation
ENABLE_SMTP // For SMTP class compilation
ENABLE_NTP_TIME // For enabling the device or library time setup from NTP server
ENABLE_ERROR_STRING // For enabling the error string from error reason
ESP_MAIL_USE_PSRAM // For enabling PSRAM support
ESP_MAIL_DEFAULT_FLASH_FS // For enabling Flash filesystem support
ESP_MAIL_DEFAULT_SD_FS // For enabling SD filesystem support 
ESP_MAIL_CARD_TYPE_SD or ESP_MAIL_CARD_TYPE_SD_MMC // The SD card type for SD filesystem

The Flash and SD filesystems are predefined.

SD is the default SD filesystem for all devices.

For ESP8266 and Arduino Pico, LittleFS is the default flash filesystem.

For ESP32 since v2.0.x, LittleFS is the default flash filesystem otherwise SPIFFS is the default flash filesystem.

In otherr devices, SPIFFS is the default flash filesystem.

User can change ESP_MAIL_DEFAULT_FLASH_FS and ESP_MAIL_DEFAULT_SD_FS with ESP_MAIL_CARD_TYPE_SD or ESP_MAIL_CARD_TYPE_SD_MMC defined values for other filesystems.

Optional Options

The following options are not yet defined in ESP_Mail_FS.h and can be assigned by user.

SILENT_MODE // For silent operation (no debug printing and callback)
ESP_MAIL_ETHERNET_MODULE_LIB `"EthernetLibrary.h"` // For the Ethernet library to work with external Ethernet module
ESP_MAIL_ETHERNET_MODULE_CLASS EthernetClass // For the Ethernet class object of Ethernet library to work with external Ethernet module
ESP_MAIL_ETHERNET_MODULE_TIMEOUT 2000 // For the time out in milliseconds to wait external Ethernet module to connect to network
ENABLE_ESP8266_ENC28J60_ETH //  For ENC28J60 Ethernet module support in ESP8266
ENABLE_ESP8266_W5500_ETH // For W5500 Ethernet module support in ESP8266
ENABLE_ESP8266_W5100_ETH // For W5100 Ethernet module support in ESP8266
ESP_MAIL_DISABLE_ONBOARD_WIFI // For disabling on-board WiFI functionality in case external Client usage
ESP_MAIL_DISABLE_NATIVE_ETHERNET // For disabling native (sdk) Ethernet functionality in case external Client usage
ESP_MAIL_DISABLE_SSL // // For disabling SSL connection (also disabling TLS using STARTTLS) in MAP and SMTP application 
ESP_MAIL_DEBUG_PORT // For debug port assignment if SILENT_MODE option was not set

You can assign the optional build options using one of the following methods.

  • By creating user config file Custom_ESP_Mail_FS.h in library installed folder and define these optional options.

  • By adding compiler build flags with -D name.

In PlatformIO IDE, using build_flags in PlatformIO IDE's platformio.ini is more convenient

build_flags = -D ESP_MAIL_DEBUG_PORT=Serial
              -D DISABLE_IMAP
              -D ESP_MAIL_DISABLE_ONBOARD_WIFI

For external Ethernet module integation used with function setEthernetClient, both ESP_MAIL_ETHERNET_MODULE_LIB and ESP_MAIL_ETHERNET_MODULE_CLASS should be defined.

ESP_MAIL_ETHERNET_MODULE_LIB is the Ethernet library name with extension (.h) and should be inside "" or <> e.g. "Ethernet.h".

ESP_MAIL_ETHERNET_MODULE_CLASS is the name of static object defined from class e.g. Ethernet.

ESP_MAIL_ETHERNET_MODULE_TIMEOUT is the time out in milliseconds to wait network connection.

For disabling predefined options instead of editing the ESP_Mail_FS.h or using #undef in Custom_ESP_Mail_FS.h, you can define these build flags with these names or macros in Custom_ESP_Mail_FS.h.

DISABLE_IMAP // For excluding the IMAP class compilation
DISABLE_SMTP // For excluding the SMTP class compilation
DISABLE_NTP_TIME // For disabling the NTP time setting
DISABLE_ERROR_STRING // For disabling the error string from error reason
DISABLE_PSRAM // For disabling PSRAM support
DISABLE_FLASH // For disabling flash filesystem support
DISABLE_SD // For disabling SD filesystem support

DISABLE_ALL_OPTIONS // For disabling all predefined build options above

Note that, Custom_ESP_Mail_FS.h for user config should be placed in the library install folder inside src folder.

This Custom_ESP_Mail_FS.h will not change or overwrite when update the library.

Usage

See examples folder for all usage examples.

See src/README.md for the functions descriptions.

The usefull blogs that described how to send and read E-mail in detail can be found here.

ESP32 Send Emails using an SMTP Server: HTML, Text, and Attachments (Arduino IDE) by Rui and Sara from randomnerdtutorials.com

Receiving Emails with ESP32 using IMAP Server by Alina Mybeth from theengineeringprojects.com

The following code snippet showed the minimum usage of the library.

Send Email message

The following code will send email with image attachment.

// Include WiFi library
#include <Arduino.h>
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#elif  __has_include(<WiFiNINA.h>)
#include <WiFiNINA.h>
#elif __has_include(<WiFi101.h>)
#include <WiFi101.h>
#endif

// Include ESP Mail Client library (this library)
#include <ESP_Mail_Client.h>


// Declare the global used SMTPSession object for SMTP transport
SMTPSession smtp;

// Declare the global used Session_Config for user defined session credentials
Session_Config config;

// Callback function to get the Email sending status
void smtpCallback(SMTP_Status status);

void setup()
{

  Serial.begin(115200);

  WiFi.begin("<ssid>", "<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();

  // Set the session config
  config.server.host_name = "smtp.office365.com"; // for outlook.com
  config.server.port = 587; // for TLS with STARTTLS or 25 (Plain/TLS with STARTTLS) or 465 (SSL)
  config.login.email = "your Email address"; // set to empty for no SMTP Authentication
  config.login.password = "your Email password"; // set to empty for no SMTP Authentication
  
  // For client identity, assign invalid string can cause server rejection
  config.login.user_domain = "client domain or public ip";  

  /*
   Set the NTP config time
   For times east of the Prime Meridian use 0-12
   For times west of the Prime Meridian add 12 to the offset.
   Ex. American/Denver GMT would be -6. 6 + 12 = 18
   See https://en.wikipedia.org/wiki/Time_zone for a list of the GMT/UTC timezone offsets
   */
  config.time.ntp_server = "pool.ntp.org,time.nist.gov";
  config.time.gmt_offset = 3;
  config.time.day_light_offset = 0;

  // Declare the SMTP_Message class variable to handle to message being transport
  SMTP_Message message;

  // Set the message headers
  message.sender.name = "My Mail";
  message.sender.email = "sender or your Email address";
  message.subject = "Test sending Email";
  message.addRecipient("name1", "email1");
  message.addRecipient("name2", "email2");

  message.addCc("email3");
  message.addBcc("email4");

  // Set the message content
  message.text.content = "This is simple plain text message";

  //Base64 data of image
  const char *greenImg = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAoUlEQVR42u"
                         "3RAQ0AMAgAoJviyWxtAtNYwzmoQGT/eqwRQoQgRAhChCBECEKECBGCECEI"
                         "EYIQIQgRghCECEGIEIQIQYgQhCBECEKEIEQIQoQgBCFCECIEIUIQIgQhCB"
                         "GCECEIEYIQIQhBiBCECEGIEIQIQQhChCBECEKEIEQIQhAiBCFCECIEIUIQ"
                         "ghAhCBGCECEIEYIQIUKEIEQIQoQg5LoBBaDPbQYiMoMAAAAASUVORK5CYII=";

  // Declare the attachment data
  SMTP_Attachment att;

  // Set the attatchment info
  att.descr.filename = "green.png";
  att.descr.mime = "image/png";
  att.blob.data = (uint8_t *)greenImg;
  att.blob.size = strlen(greenImg);
  // Set the transfer encoding to base64
  att.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64;
  // We set the content encoding to match the above greenImage data
  att.descr.content_encoding = Content_Transfer_Encoding::enc_base64;

  // Add attachment to the message
  message.addAttachment(att);

  // Set debug option
  smtp.debug(1);

  // Set the callback function to get the sending results
  smtp.callback(smtpCallback);

  // Connect to the server
  smtp.connect(&config);

  // Start sending Email and close the session
  if (!MailClient.sendMail(&smtp, &message))
    Serial.println("Error sending Email, " + smtp.errorReason());

}

void smtpCallback(SMTP_Status status)
{
 
  Serial.println(status.info());

  if (status.success())
  {
    // See example for how to get the sending result
  }
}

Read Email message

The following code will read the latest email message in the "INBOX" mailbox.

// Include WiFi library
#include <Arduino.h>
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#elif  __has_include(<WiFiNINA.h>)
#include <WiFiNINA.h>
#elif __has_include(<WiFi101.h>)
#include <WiFi101.h>
#endif

// Include ESP Mail Client library (this library)
#include <ESP_Mail_Client.h>

// Declare the global used IMAPSession object for IMAP transport
IMAPSession imap;

// Declare the global used Session_Config for user defined session credentials
Session_Config config;

// Callback function to get the Email reading status
void imapCallback(IMAP_Status status)

void setup()
{

  Serial.begin(115200);

  WiFi.begin("<ssid>", "<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();

  // Set the session config
  config.server.host_name = "outlook.office365.com"; //for outlook.com
  config.server.port = 993; // for SSL or 143 for Plain or TLS with STARTTLS
  config.login.email = "your Email address";
  config.login.password = "your Email password";

  // Declare the IMAP_Data object used for user defined IMAP operating options 
  // and contains the IMAP operating result
  IMAP_Data imap_data;

  
  // Set to enable the message content which will be stored in the IMAP_Data data
  imap_data.enable.html = true;
  imap_data.enable.text = true;


  // Set the debug option
  imap.debug(1);

  // Set the callback function to get message information
  imap.callback(imapCallback);


  // Connect to the server
  imap.connect(&config, &imap_data);

  // Open or select the mailbox folder to read the message
  imap.selectFolder("INBOX");


  // Define the message UID (number) which required to fetch or read the message
  // In this case we will get the UID from the max message number (lastest message)
  // then imap.getUID and imap.selectedFolder().msgCount() should be called after 
  // calling select or open the folder (mailbox).
  imap_data.fetch.uid = imap.getUID(imap.selectedFolder().msgCount());

  // Empty search criteria to disable the messsage search
  imap_data.search.criteria.clear();


  // Read the Email and close the session
  MailClient.readMail(&imap);


}


void imapCallback(IMAP_Status status)
{
    
    Serial.println(status.info());

    if (status.success())
    {
        // See example for how to get the message info 
    }
}

Get Mailbox Changes Notification

See Mailbox_Changes_Notification.ino for the example.

Sending Custom IMAP commands

Can't find what you want from exising IMAP functions, sending custom command was supported.

Please read the RFC 3501 and RFC 9051 documents for the details of IMAP protocol commands.

See Custom_Command examples for how to use.

Using TCP session KeepAlive in ESP8266 and ESP32

The server connection will be probed at some intervals to maintain connection.

The TCP session KeepAlive can be enabled from executing <SMTPSession>.keepAlive or <IMAPSession>.keepAlive with providing TCP options as arguments, i.e.,

tcpKeepIdleSeconds, tcpKeepIntervalSeconds and tcpKeepCount.

Ex.

smtp.keepAlive(5 /* tcp KeepAlive idle 5 seconds */, 5 /* tcp KeeAalive interval 5 seconds */, 1 /* tcp KeepAlive count 1 */);

imap.keepAlive(5 /* tcp KeepAlive idle 5 seconds */, 5 /* tcp KeeAalive interval 5 seconds */, 1 /* tcp KeepAlive count 1 */);

// If one of three arguments is zero, the KeepAlive will be disabled.

To check the KeepAlive status, use <SMTPSession>.isKeepAlive or <IMAPSession>.isKeepAlive.

For the TCP (KeepAlive) options, see here.

You can check the server connecting status, by executing <SMTPSession>.connected() or <IMAPSession>.connected() which will return true when connection to the server is still alive.

The TCP KeepAlive was currently available in ESP32 unless in ESP8266, this ESP8266 PR #8940 should be merged in the ESP8266 Arduino Core SDK, i.e., it will be supported in the ESP8266 core version newer than v3.1.2.

In ESP8266 core v3.1.2 and older, the error can be occurred when executing <SMTPSession>.keepAlive or <IMAPSession>.isKeepAlive because of object slicing.

The Arduino Pico is currently not support TCP KeepAlive until it's implemented in WiFiClientSecure library as in ESP8266.

For External Client, this TCP KeepAlive option is not appliable and should be managed by external Client library.

Use External Arduino Clients for External Networking Devices

This library supports external netwoking devices e.g. WiFi modules, Ethernet modules and GSM modules that connected to the Arduino device via communication ports e.g. SPI and Serial, through the Arduino Clients (driver) for those networking devices e.g. WiFiClient, EthernetClient and GSMClient.

Since v3.4.0, the Arduino Clients can be used with this library without additional external SSL Client required.

No additional setup needed, only pass the Arduino Client to the function setClient or pass the TinyGSMClient and TinyGSM modem to the function setGSMClient or pass the Ethernet client and mac address to the function setEthernetClient.

Two callback functions are required (except for setGSMClient and setEthernetClient) for network connection (with disconnection) and sending connecting status back to the Mail Client.

If device has on-board WiFi and supports native (SDK) Ethernet, these two native networks will be auto detectd and used.

If you don't want to let ESP Mail Client library to use the native networking and use external networking devices using Arduino Clients instead, the following build flags or macros should be defined in Custom_ESP_Mail_FS.h.

ESP_MAIL_DISABLE_ONBOARD_WIFI

ESP_MAIL_DISABLE_NATIVE_ETHERNET

See External Client Examples for more external Client usage.

TTGO T-A7670 LTE with TinyGSM

The following example showed how to use TTGO T-A7670 with GSMClient to connect to SMTP server.

To allow TinyGSM library integration, the following build flag or macro should be defined in Custom_ESP_Mail_FS.h.

TINY_GSM_MODEM_SIM7600

See the TinyGSM documentation and example for other SIMCom modules definition.

// For TTGO T-A7670
#define TINY_GSM_MODEM_SIM7600 // SIMA7670 Compatible with SIM7600 AT instructions

// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial

// Set serial for AT commands (to the module)
// Use Hardware Serial on Mega, Leonardo, Micro
#define SerialAT Serial1

// See all AT commands, if wanted
// #define DUMP_AT_COMMANDS

// Define the serial console for debug prints, if needed
#define TINY_GSM_DEBUG SerialMon

#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false

// set GSM PIN, if any
#define GSM_PIN ""

// Your GPRS credentials, if any
const char apn[] = "YourAPN";
const char gprsUser[] = "";
const char gprsPass[] = "";


#define uS_TO_S_FACTOR 1000000ULL // Conversion factor for micro seconds to seconds
#define TIME_TO_SLEEP 600         // Time ESP32 will go to sleep (in seconds)

#define UART_BAUD 115200
#define PIN_DTR 25
#define PIN_TX 26
#define PIN_RX 27
#define PWR_PIN 4
#define BAT_ADC 35
#define BAT_EN 12
#define PIN_RI 33
#define PIN_DTR 25
#define RESET 5

#define SD_MISO 2
#define SD_MOSI 15
#define SD_SCLK 14
#define SD_CS 13


#include <ESP_Mail_Client.h>
#include <TinyGsmClient.h>


TinyGsm modem(SerialAT);

TinyGsmClient gsm_client(modem); // basic non-secure client

SMTPSession smtp;

// Callback function to get the Email sending status
void smtpCallback(SMTP_Status status);

void setup()
{

  SerialMon.begin(115200);
  
  // Set debug option
  smtp.debug(1);

  // Set the callback function to get the sending results
  smtp.callback(smtpCallback);

  delay(10);
  pinMode(BAT_EN, OUTPUT);
  digitalWrite(BAT_EN, HIGH);

  // A7670 Reset
  pinMode(RESET, OUTPUT);
  digitalWrite(RESET, LOW);
  delay(100);
  digitalWrite(RESET, HIGH);
  delay(3000);
  digitalWrite(RESET, LOW);

  pinMode(PWR_PIN, OUTPUT);
  digitalWrite(PWR_PIN, LOW);
  delay(100);
  digitalWrite(PWR_PIN, HIGH);
  delay(1000);
  digitalWrite(PWR_PIN, LOW);

  DBG("Wait...");

  delay(3000);

  SerialAT.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX);

  // Restart takes quite some time
  // To skip it, call init() instead of restart()
  DBG("Initializing modem...");
  if (!modem.init())
  {
    DBG("Failed to restart modem, delaying 10s and retrying");
    return;
  }

  /*
  2 Automatic
  13 GSM Only
  14 WCDMA Only
  38 LTE Only
  */
  modem.setNetworkMode(38);
  if (modem.waitResponse(10000L) != 1)
  {
    DBG(" setNetworkMode faill");
  }

  String name = modem.getModemName();
  DBG("Modem Name:", name);

  String modemInfo = modem.getModemInfo();
  DBG("Modem Info:", modemInfo);

  Session_Config config;

  config.server.host_name = SMTP_HOST;
  config.server.port = SMTP_PORT;
  config.login.email = AUTHOR_EMAIL;
  config.login.password = AUTHOR_PASSWORD;
  config.login.user_domain = F("127.0.0.1");

  // Declare the SMTP_Message class variable to handle to message being transport
  SMTP_Message message;

  // Set the message headers
  message.sender.name = F("ESP Mail");
  message.sender.email = AUTHOR_EMAIL;
  message.subject = F("Test sending plain text Email using GSM module");
  message.addRecipient(F("Someone"), RECIPIENT_EMAIL);

  // Set the message content
  message.text.content = "This is simple plain text message";
 
  // Set debug option
  smtp.debug(1);

  // Set the callback function to get the sending results
  smtp.callback(smtpCallback);

  smtp.setGSMClient(&gsm_client, &modem, GSM_PIN, apn, gprsUser, gprsPass);

  // Connect to the server with the defined session and options
  smtp.connect(&config);

  // Start sending Email and close the session
  if (!MailClient.sendMail(&smtp, &message))
    Serial.println("Error sending Email, " + smtp.errorReason());
}

void loop()
{
}

void smtpCallback(SMTP_Status status)
{
 
  Serial.println(status.info());

  if (status.success())
  {
    // See example for how to get the sending result
  }
}

ESP32 and W5500

The below example will use ESP32 and W5500 and Ethernet client library to connect to SMTP server

#include <Ethernet.h>

#include <ESP_Mail_Client.h>

#define WIZNET_RESET_PIN 26 // Connect W5500 Reset pin to GPIO 26 of ESP32
#define WIZNET_CS_PIN 5     // Connect W5500 CS pin to GPIO 5 of ESP32
#define WIZNET_MISO_PIN 19  // Connect W5500 MISO pin to GPIO 19 of ESP32
#define WIZNET_MOSI_PIN 23  // Connect W5500 MOSI pin to GPIO 23 of ESP32
#define WIZNET_SCLK_PIN 18  // Connect W5500 SCLK pin to GPIO 18 of ESP32


uint8_t Eth_MAC[] = {0x02, 0xF0, 0x0D, 0xBE, 0xEF, 0x01};

SMTPSession smtp;

EthernetClient eth_client;

void smtpCallback(SMTP_Status status);

void setup()
{
    Serial.begin(115200);

    config.server.host_name = "smtp.gmail.com"; //for gmail.com
    config.server.port = 587; // requires connection upgrade via STARTTLS
    config.login.email = "your Email address"; //set to empty for no SMTP Authentication
    config.login.password = "your Email password"; //set to empty for no SMTP Authentication
    config.login.user_domain = "client domain or ip e.g. mydomain.com";

    // Declare the SMTP_Message class variable to handle to message being transport
    SMTP_Message message;

    // Set the message headers
    message.sender.name = "My Mail";
    message.sender.email = "sender or your Email address";
    message.subject = "Test sending Email";
    message.addRecipient("name1", "email1");
    message.addRecipient("name2", "email2");

    message.addCc("email3");
    message.addBcc("email4");

    // Set the message content
    message.text.content = "This is simple plain text message";

    smtp.setEthernetClient(&eth_client, Eth_MAC, WIZNET_CS_PIN, WIZNET_RESET_PIN); 

    // Set debug option
    smtp.debug(1);
    
    // Set the callback function to get the sending results
    smtp.callback(smtpCallback);

    // Connect to the server with the defined session and options
    smtp.connect(&config);

    // Start sending Email and close the session
    if (!MailClient.sendMail(&smtp, &message))
      Serial.println("Error sending Email, " + smtp.errorReason());
  
}

void smtpCallback(SMTP_Status status)
{
 
  Serial.println(status.info());

  if (status.success())
  {
    // See example for how to get the sending result
  }
}

Acheivement

Open Sourcs Contribution Awards

This project ESP Mail Client wins the Google Open Source Peer Bonus program.

This project would not have been possible without support from all users.

Thanks for all contributors for help, bugs fix and improvement.

Thanks for Edward Chuang (莊坪達) from Google for selecting this project.

Sponsors

Thank your for the following users whose supporting me.

@jiperez11 jiperez11

private sponsor Private sponsor

@Jagakatt Jagakatt

If you like my works, you can give a star. If you can make benefit from my project or love it, you can sponsoring me.

License

The MIT License (MIT)

Copyright (c) 2024 K. Suwatchai (Mobizt)

Permission is hereby granted, free of charge, to any person returning a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

esp-mail-client's People

Contributors

dkalliv avatar gitter-badger avatar jason2866 avatar mobizt avatar shafr avatar wildernessfamily avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp-mail-client's Issues

Lora and SD card and Mail client

My ESP connect vs Lora via SPI ( SCK: GPIO18,MISO: GPIO19,MOSI: GPIO23,CS:GPIO5 ,RTS: GPIO4,IRQ:GPIO16)
and SD ( SS:13, MOSI:15,MISO:2, SCK:14) but I use only one,if i use one then the other fails and vice versa.

erosion of free heap [irrelevant]

With:
Arduino IDE v1.8.13
ESP core v1.0.5
ESP-Mail-Client v1.0.13
Adafruit ESP32 Feather

Using code from example Send_text.ino

There is a drop in free heap with every email and slow erosion of free heap associated with email use, as shown in the attached image.

slowHeapErosion

ESP32 crashing when fetching a message(header) from an Apple iCloud IMAP account

Build tool used:

  • Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • ESP32-based

Other Libraries That are used:

Description of problem:
The ESP32 crashes when trying to fetch a message header from an iCloud IMAP account. After experiencing the issue with my own code, I was able to reproduce the same problem using the Search_Emails and Read_Single_Email examples provided with the library (I'm using Version 1.4.0). The log pasted below is produced using the unmodified (apart from wifi and imap credentials) Read_Single_Email example.

Share code snippet to reproduce the issue:

PASTE .cpp / .ino code here
Connecting to AP...........
WiFi connected.
IP address: 
XXX.XXX.XXX.XXX

Connecting to IMAP server...
> C: ESP Mail Client v1.4.0
> C: connect to IMAP server
> C: host > imap.mail.me.com
> C: port > 993
> C: starting socket
> C: connecting to Server
> C: seeding the random number generator
> C: setting up the SSL/TLS structure
! W: Skipping SSL Verification. INSECURE!
> C: setting hostname for TLS session
> C: performing the SSL/TLS handshake
> C: verifying peer X.509 certificate
IMAP server connected
> C: server connected

Check the capability...
> C: check the capability
$ CAPABILITY
* OK [CAPABILITY XAPPLEPUSHSERVICE IMAP4 IMAP4rev1 SASL-IR AUTH=ATOKEN AUTH=PLAIN] (2117B22-978ffe0c9356) st43p00im-tygg10060301.me.com
* CAPABILITY XAPPLEPUSHSERVICE IMAP4 IMAP4rev1 SASL-IR AUTH=ATOKEN AUTH=PLAIN
$ OK Completed

Logging in...
> C: send imap command, LOGIN
$ LOGIN [email protected] XXXXXXXXXXXX
$ OK user XXXXXXXX logged in

Reading the list of mailboxes...
> C: send imap command, LIST
$ LIST "" *
* LIST (\Noinferiors) "/" "INBOX"
* LIST () "/" "Trash"
* LIST () "/" "Sent"
* LIST () "/" "test"
$ OK LIST completed (took 39 ms)

Available folders: INBOX, Trash, Sent, test

Selecting the INBOX folder...
> C: open the mailbox folder
$ EXAMINE "INBOX"
* 1 EXISTS
* 0 RECENT
* OK [UNSEEN 1]
* OK [UIDVALIDITY 1]
* OK [UIDNEXT 3]
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen \Recent $MailFlagBit0 $MailFlagBit1 $MailFlagBit2 $Forwarded Redirected $NotJunk NotJunk)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen \Recent $MailFlagBit0 $MailFlagBit1 $MailFlagBit2 $Forwarded Redirected $NotJunk NotJunk \*)]
$ OK [READ-WRITE] EXAMINE completed (took 2 ms)

Info of the selected folder
Total Messages: 1
Predicted next UID: 3
Flags: \Answered, \Flagged, \Draft, \Deleted, \Seen, \Recent, $MailFlagBit0, $MailFlagBit1, $MailFlagBit2, $Forwarded, Redirected, $NotJunk, NotJunk

Fetching message 1, UID: 2
> C: send imap command, FETCH
> C: fetch message header
$ UID FETCH 2 BODY.PEEK[HEADER.FIELDS (SUBJECT FROM TO DATE CC Message-ID Accept-Language content-type Content-transfer-encoding Content-Language)]
* 1 FETCH (UID 2 BODY[HEADER.FIELDS (SUBJECT FROM TO DATE CC Message-ID Accept-Language content-type Content-transfer-encoding Content-Language)] {328}
TO: [email protected]
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x40089fc5  PS      : 0x00060830  A0      : 0x800d5c27  A1      : 0x3ffb2040  
A2      : 0x00000000  A3      : 0xfffffffc  A4      : 0x000000ff  A5      : 0x0000ff00  
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x3ffb2000  
A10     : 0x3ffdd8c8  A11     : 0x3ffde5c0  A12     : 0x3ffdd8c8  A13     : 0x00000016  
A14     : 0x00000016  A15     : 0x00000001  SAR     : 0x0000001b  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x40089fc5  LEND    : 0x40089fd5  LCOUNT  : 0xffffffff  


Backtrace:0x40089fc2:0x3ffb20400x400d5c24:0x3ffb2050 0x400d691e:0x3ffb2070 0x400e1071:0x3ffb20a0 0x400e34d5:0x3ffb2680 0x400d2aed:0x3ffb2790 0x400e9c83:0x3ffb2820 




ELF file SHA256: 0000000000000000

Rebooting...

Additional information and things you've tried:
I tried downgrading to the ESP32 1.0.6 version, but experienced the same issue as with version 2.0.0. I also tested with a simple message with only a subject and no body, but had the same results.

Problem with ISO-8859-1 encoded subject header fields

Build tool used:

  • Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • ESP32-based

Other Libraries That are used:

Description of problem:
Message subjects that are ISO-8859-1 encoded are not decoded correctly if the encoding scheme is provided in uppercase letters (same gmail apps on Android seem to be doing this). See sample message header snippet.

Share code snippet to reproduce the issue:

Subject: =?ISO-8859-1?B?5Pb8?=

Additional information and things you've tried:
I fixed the problem by converting headerEnc to lowercase. I've created a pull request with the fix.

Enable "1-bit" SD card access (as per SD_MMC)

Hi,

I read some old threads where people using ESP32-CAM boards wanted to attach an image saved to SD card from the camera. Many of these examples seem to be based on a tutorial using SD_MMC rather than SD, which I understand is not compatible with ESP Mail.

However, unless I'm mistaken, one of the reasons for using SD_MMC is that, by passing "true" as the third parameter value, it can be initialized in "1 bit mode", which crucially frees up pins 12 and 13 from the SPI interface. Unfortunately, I can't see an equivalent overload for the sdBegin() method of MailClient - it seems to require the full 4-pin SPI interface, which means there are no spare GPIO pins on an ESP32-CAM board. I'd be grateful if you could verify my understanding or whether there's a workaround? Thankyou!

run led

How to operate led (Esp32 gpio 2) with the email matching received with hi imap.
#define textmessage1 "on"
#define textmessage2 "off"
.
.
.
.
if(msg.text.content == textmessage1){
digitalWrite(2,HIGH);
}
if(msg.text.content == textmessage2){
digitalWrite(2,LOW);
}
?

Example of SSL/TLS using a rootCA

Build tool used:

  • Arduino IDE
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • ESP32-based

Other Libraries That are used:

Description of problem:
I have successfully used this library to send emails using gmail and SSL/TLS using port 587, but without setting the option to verify the certificate. However for security reasons it would be good to verify the root CA. I have tried in several ways to use it, and no connection. I always get in the debug log in my serial console,the following:

Send command, STARTTLS
C: send STARTTLS command
220 2.0.0 Ready to start TLS
< S: 220 2.0.0 Ready to start TLS
C: performing the SSL/TLS handshake
C: seeding the random number generator
C: setting up the SSL/TLS structure
C: cleaning SSL connection
Error, fail to set up the SSL/TLS structure
E: fail to set up the SSL/TLS structure

It would be great to include an example on how to use the
session.certificate.verify = true;

how to specify the root certificate and how to specify the other necessary options to be set.

Thank you!

Share code snippet to reproduce the issue:

PASTE .cpp / .ino code here

Additional information and things you've tried:

/* Set the session config */
session.server.host_name = SMTP_HOST; // This is "smtp.gmail.com"
session.server.port = SMTP_PORT; // This is 587
session.login.email = AUTHOR_EMAIL;
session.login.password = AUTHOR_PASSWORD;
session.login.user_domain = MY_DOMAIN; // here the real domain being used
session.certificate.verify = true;
session.certificate.cert_data = GSR2_PEM; // This is a pem of the GlobalSign R2 CA PEM

SelectedFolderInfo is no longer updated with every call of selectFolder

Build tool used:

  • Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • ESP32-based

Other Libraries That are used:

Description of problem:
In library version 1.5.6 SelectedFolderInfo is no longer updated with every call of selectFolder (this was working with version 1.5.5). In the example below msgCount() and nextUID() remain the same, even though, a new message was received after the first iteration.

Share code snippet to reproduce the issue:

/**
 * This example will search all Emails in the opened mailbox folder.
 * 
 * Created by K. Suwatchai (Mobizt)
 * 
 * Email: [email protected]
 * 
 * Github: https://github.com/mobizt/ESP-Mail-Client
 * 
 * Copyright (c) 2021 mobizt
 *
*/

/** To receive Email using Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en
 * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha
 * 
*/

/** For ESP8266, with BearSSL WiFi Client 
 * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which
 * may cause your device out of memory reset in case the memory 
 * allocation error.
*/

#include <Arduino.h>
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include <ESP_Mail_Client.h>

//To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h.

#define WIFI_SSID "xxxxxx"
#define WIFI_PASSWORD "xxxxxxxxx"

/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */
#define IMAP_HOST "xxxxx.xxxxx.xxxx.xxx"

/** The imap port e.g. 
 * 143  or esp_mail_imap_port_143
 * 993 or esp_mail_imap_port_993
*/
#define IMAP_PORT 993

/* The log in credentials */
#define AUTHOR_EMAIL "[email protected]"
#define AUTHOR_PASSWORD "xxxxxxxxx"

/* Print the selected folder info */
void printSelectedMailboxInfo(SelectedFolderInfo sFolder);

/* The IMAP Session object used for Email reading */
IMAPSession imap;

void setup()
{

    Serial.begin(115200);

#if defined(ARDUINO_ARCH_SAMD)
    while (!Serial)
        ;
    Serial.println();
    Serial.println("**** Custom built WiFiNINA firmware need to be installed.****\nTo install firmware, read the instruction here, https://github.com/mobizt/ESP-Mail-Client#install-custom-built-wifinina-firmware");

#endif

    Serial.println();

    Serial.print("Connecting to AP");

    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    while (WiFi.status() != WL_CONNECTED)
    {
        Serial.print(".");
        delay(200);
    }

    Serial.println("");
    Serial.println("WiFi connected.");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    Serial.println();

    imap.debug(333);


    /* Declare the session config data */
    ESP_Mail_Session session;



    /* Set the session config */
    session.server.host_name = IMAP_HOST;
    session.server.port = IMAP_PORT;
    session.login.email = AUTHOR_EMAIL;
    session.login.password = AUTHOR_PASSWORD;

    /* Setup the configuration for searching or fetching operation and its result */
    IMAP_Config config;

    /* Message UID to fetch or read */
    config.fetch.uid = "";


    config.search.criteria = "UID SEARCH ALL";

    /* Also search the unseen message */
    config.search.unseen_msg = true;

    /* Set the storage to save the downloaded files and attachments */
    config.storage.saved_path = "/email_data";

    config.storage.type = esp_mail_file_storage_type_flash;

    /** Set to download heades, text and html messaeges, 
     * attachments and inline images respectively.
    */
    config.download.header = true;
    config.download.text = true;
    config.download.html = true;
    config.download.attachment = true;
    config.download.inlineImg = true;

    config.enable.html = true;
    config.enable.text = true;

    /* Set to enable the sort the result by message UID in the ascending order */
    config.enable.recent_sort = true;

    /* Set to report the download progress via the default serial port */
    config.enable.download_status = true;


    /* Set the limit of number of messages in the search results */
    config.limit.search = 40;

    /** Set the maximum size of message stored in 
     * IMAPSession object in byte
    */
    config.limit.msg_size = 512;


    config.limit.attachment_size = 1024 * 1024 * 5;


    /* Connect to server with the session and config */
    if (!imap.connect(&session, &config))
        return;

    /* Open or select the mailbox folder to read or search the message */
    if (!imap.selectFolder("INBOX"))
        return;

}

void loop()
{ 
  if (!imap.selectFolder("INBOX"))
        return;
  printSelectedMailboxInfo(imap.selectedFolder());
  delay(10000);
}

void printSelectedMailboxInfo(SelectedFolderInfo sFolder)
{
    /* Show the mailbox info */
    ESP_MAIL_PRINTF("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount());
    ESP_MAIL_PRINTF("Predicted next UID: %d\n", sFolder.nextUID());
    for (size_t i = 0; i < sFolder.flagCount(); i++)
        ESP_MAIL_PRINTF("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : "");
}

Here is the serial output:

Connecting to AP...........
WiFi connected.
IP address: 
xxx.xxx.xxx.xxx

> C: ESP Mail Client v1.5.6
> C: connect to IMAP server
> C: host > xxxx.xxxxxxxxxxxx.xxx.xx
> C: port > 993
> C: starting socket
> C: connecting to Server
> C: seeding the random number generator
> C: setting up the SSL/TLS structure
! W: Skipping SSL Verification. INSECURE!
> C: setting hostname for TLS session
> C: performing the SSL/TLS handshake
> C: verifying peer X.509 certificate
> C: server connected
> C: check the capability
$ CAPABILITY
* OK swizzonic-mail.ch CommuniGate Pro IMAP Server 7.1.0 ready
* CAPABILITY IMAP4 IMAP4REV1 ACL NAMESPACE UIDPLUS IDLE LITERAL+ QUOTA ID MULTIAPPEND LISTEXT CHILDREN BINARY ESEARCH LOGIN-REFERRALS UNSELECT SASL-IR LIST-EXTENDED SPECIAL-USE CREATE-SPECIAL-USE XLIST AUTH=LOGIN AUTH=PLAIN
$ OK completed
> C: send imap command, LOGIN
$ LOGIN [email protected] xxxxxxxxxxxxxx
$ OK completed
> C: open the mailbox folder
$ EXAMINE "INBOX"
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Hidden $Media $Forwarded Junk $Label1 $Label2 $Label3)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Hidden $Media $Forwarded Junk $Label1 $Label2 $Label3)] limited
* 37 EXISTS
* 0 RECENT
* OK [UIDNEXT 1934] predicted next UID
* OK [UIDVALIDITY 402270099] UIDs valid
* OK [UNSEEN 3] message 3 is first unseen
$ OK [READ-ONLY] EXAMINE completed

Info of the selected folder
Total Messages: 37
Predicted next UID: 1934
Flags: \Answered, \Flagged, \Deleted, \Seen, \Draft, $MDNSent, $Hidden, $Media, $Forwarded, Junk, $Label1, $Label2, $Label3

Info of the selected folder
Total Messages: 37
Predicted next UID: 1934
Flags: \Answered, \Flagged, \Deleted, \Seen, \Draft, $MDNSent, $Hidden, $Media, $Forwarded, Junk, $Label1, $Label2, $Label3

Info of the selected folder
Total Messages: 37
Predicted next UID: 1934
Flags: \Answered, \Flagged, \Deleted, \Seen, \Draft, $MDNSent, $Hidden, $Media, $Forwarded, Junk, $Label1, $Label2, $Label3

Additional information and things you've tried:
When calling closeFolder() and empty() before selectFolder() then SelectedFolderInfo seems to be updated as expected.

Warning in ESP8266

Hello,
i get a warning in the library ESP_Mail_Client V1.3.0 when i compile my project in Arduino.
Message:
/mnt/01D1A901D0770EE0/LinuxPortable/arduino/portable/sketchbook/libraries/ESP_Mail_Client/src/wcs/esp8266/ESP8266_TCP_Client.cpp: In member function 'int ESP8266_TCP_Client::send(const char*)':
/mnt/01D1A901D0770EE0/LinuxPortable/arduino/portable/sketchbook/libraries/ESP_Mail_Client/src/wcs/esp8266/ESP8266_TCP_Client.cpp:97:1: warning: control reaches end of non-void function [-Wreturn-type]
97 | }
| ^

Example "Read_single_Email" can't receive attachment

Build tool used:

  • Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • ESP32-based

Other Libraries That are used:

Description of problem:
I tested example “Send_Attachment_File” and send email to mail box ([email protected] ). I found send is ok,but when I used example “Read_single_Email” to receive ,email subject can display ok,but the attached files not be receive.

Share code snippet to reproduce the issue:

    /* Set the session config */
    session.server.host_name = IMAP_HOST;
    session.server.port = IMAP_PORT;
    session.login.email = AUTHOR_EMAIL;
    session.login.password = AUTHOR_PASSWORD;


    /* Setup the configuration for searching or fetching operation and its result */
    IMAP_Config config;

    /* Message UID to fetch or read e.g. 100 */
    config.fetch.uid = "";

    /* Set seen flag */
    //config.fetch.set_seen = true;

    /* Search criteria */
    config.search.criteria = "UID SEARCH ALL";

    /* Also search the unseen message */
    config.search.unseen_msg = true;

    /* Set the storage to save the downloaded files and attachments */
    config.storage.saved_path = "/email_data";

    /** The file storage type e.g.
     * esp_mail_file_storage_type_none,
     * esp_mail_file_storage_type_flash, and 
     * esp_mail_file_storage_type_sd 
    */
    config.storage.type = esp_mail_file_storage_type_none;

    /** Set to download heades, text and html messaeges, 
     * attachments and inline images respectively.
    */
    config.download.header = true;
    config.download.text = true;
    config.download.html = true;
    config.download.attachment = true;
    config.download.inlineImg = true;

    /** Set to enable the results i.e. html and text messaeges 
     * which the content stored in the IMAPSession object is limited
     * by the option config.limit.msg_size.
     * The whole message can be download through config.download.text
     * or config.download.html which not depends on these enable options.
    */
    config.enable.html = true;
    config.enable.text = true;

    /* Set to enable the sort the result by message UID in the ascending order */
    config.enable.recent_sort = true;

    /* Set to report the download progress via the default serial port */
    config.enable.download_status = true;

    /* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud
    , to allow case sensitive parse, uncomment below line*/
    //config.enable.header_case_sesitive = true;

    /* Set the limit of number of messages in the search results */
    config.limit.search = 5;

    /** Set the maximum size of message stored in 
     * IMAPSession object in byte
    */
    config.limit.msg_size = 512;

    /** Set the maximum attachments and inline images files size
     * that can be downloaded in byte. 
     * The file which its size is largger than this limit may be saved 
     * as truncated file.
    */
    config.limit.attachment_size = 1024 * 1024 * 5;


    /* Connect to server with the session and config */
    if (!imap.connect(&session, &config))
        return;

    /*  {Optional] */
    printAllMailboxesInfo(imap);

    /* Open or select the mailbox folder to read or search the message */
    if (!imap.selectFolder("INBOX"))
        return;

    /*  {Optional] */
    printSelectedMailboxInfo(imap);
    //if (MailClient.setFlag(&imap, 24, "\\Seen", false))
    //    Serial.println("Setting FLAG success");
    //else
    //    Serial.println("Error, setting FLAG");
    /* Read or search the Email and close the session */
    MailClient.readMail(&imap);

Additional information and things you've tried:
Connecting to IMAP server...

C: ESP Mail Client v1.4.2
C: connect to IMAP server
C: host > outlook.office365.com
C: port > 993
C: starting socket
C: connecting to Server
C: seeding the random number generator
C: setting up the SSL/TLS structure
! W: Skipping SSL Verification. INSECURE!
C: setting hostname for TLS session
C: performing the SSL/TLS handshake
C: verifying peer X.509 certificate
IMAP server connected
C: server connected

Check the capability...

C: check the capability

Logging in...

C: send imap command, LOGIN

Reading the list of mailboxes...

C: send imap command, LIST

Available folders: Notes, Drafts, &W1hoYw-, Outbox, Junk, Inbox, Sent, Deleted

Selecting the INBOX folder...

C: open the mailbox folder

Info of the selected folder
Total Messages: 1
Predicted next UID: 41
Flags: \Seen, \Answered, \Flagged, \Deleted, \Draft, $MDNSent

Searching messages...

C: search messages
C: 100%

Search limit:5
Found 1 messages
Show 1 messages

Fetching message 1, UID: 38

C: send imap command, FETCH
C: fetch message header
C: Free Heap: 231592

Logging out...

C: send imap command, LOGOUT

Message fetch cmpleted

C: message fetch completed
C: cleaning SSL connection

################################
Messsage Number: 1
Messsage UID: 38
Messsage ID: SG2PR02MB44430233B5F997CA75C61B6CC9D99@SG2PR02MB4443.apcprd02.prod.outlook.com
Accept Language:
Content Language:
From: ESP Mail[email protected]
From Charset:
To: user1[email protected]
To Charset:
CC:
CC Charset:
Date: Mon, 13 Sep 2021 08:04:52 +0000
Subject: Test sending Email with attachments and inline images from SD card and Flash
Subject Charset:

Soft WDT reset after "Wait for NTP server time synching"

Build tool used:
Arduino

Board used (ESP32/ESP8266/Arudino):
ESP8266

Other Libraries That are used:

#include <ESP8266WiFi.h>
#include <ESPAsyncUDP.h>
#include <Pinger.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include <ESP_EEPROM.h>
#include <mdns.h>
#include <ESP_Mail_Client.h>

Description of problem:
Soft WDT reset when sending email:

Sending email"\<�? " to [email protected]. Company: Unhackable Smart Home®
Connecting to SMTP server...
> C: ESP Mail Client v2.3.1
> C: Wait for NTP server time synching

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset
...

Share code snippet to reproduce the issue:

void send_alert(const char *name, const char *IP_str)
{
  SMTP_Message message;
  message.sender.name = "Unhackable Smart Home\u00AE";
  message.sender.email = AUTHOR_EMAIL;
  message.subject = std::string(name) + " has arrived!";
  message.addRecipient("Home", RECIPIENT_EMAIL);
  Serial.printf("Sending email\"%s\" to %s.\n" , message.subject, RECIPIENT_EMAIL);

  std::string htmlMsg = std::string("<h1>") + name + " joined the network!</h1><br><p>Device " + name + " (" + IP_str + ")</p>";
  message.html.content = htmlMsg;
  message.text.charSet = "us-ascii";
  message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit;

  if (!smtp.connect(&session)) // connect
    return;                    // return if not connected

  if (!MailClient.sendMail(&smtp, &message))
    Serial.println("Error sending Email, " + smtp.errorReason());
}

ESP32 Reboot

Connecting to SMTP server...

C: connect to SMTP server
C: host > smtp.126.com
C: port > 465
C: smtp server connected

SMTP server connected, wait for greeting...
< S: 220 126.com Anti-spam GT for Coremail System (126com[20140526])

Sending greeting response...

C: send smtp command, HELO
< S: 250-mail
< S: 250-PIPELINING
< S: 250-AUTH LOGIN PLAIN
< S: 250-AUTH=LOGIN PLAIN
< S: 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2Ur9ozT7UCa0xDrUUUUj
< S: 250-STARTTLS
< S: 250 8BITMIME

Send command, STARTTLS

C: send STARTTLS command
< S: 454 Command not permitted when TLS active
Error, SMTP server greeting failed
E: SMTP server greeting failed
assertion "heap != NULL && "free() target pointer is outside heap areas"" failed: file "/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c", line 267, function: heap_caps_free
abort() was called at PC 0x4015bbd7 on core 1

Backtrace: 0x4008cf08:0x3ffd66c0 0x4008d139:0x3ffd66e0 0x4015bbd7:0x3ffd6700 0x40084d9f:0x3ffd6730 0x400851ad:0x3ffd6750 0x4000bec7:0x3ffd6770 0x40193889:0x3ffd6790 0x4019da56:0x3ffd67b0 0x400d6137:0x3ffd67d0 0x400d664a:0x3ffd67f0 0x400e0481:0x3ffd6a70 0x400e0509:0x3ffd6ce0 0x400eb565:0x3ffd6d00 0x400e8f49:0x3ffd6d40 0x400e8fd9:0x3ffd6d80 0x401af8e1:0x3ffd6da0 0x401af971:0x3ffd6de0 0x401b0016:0x3ffd6e00 0x4008961d:0x3ffd6e30

Rebooting...

startTLS

Build tool used:

  • [ x] Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):
Lolin(wemos) D1 R2 & Mini

  • [x ] ESP8266-based
  • ESP32-based

Other Libraries That are used:

none

Description of problem:

we have the problem that we dont get a startTLS connection. he refuse TLS on Port 143.
Port: 993 SSL works great.

16:41:13.426 -> IMAP server connected
16:41:13.426 -> > server connected
16:41:13.426 ->
16:41:13.426 -> Check the capability...
16:41:13.426 -> > check the capability
16:41:13.426 -> * OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ STARTTLS LOGINDISABLED AUTH=CRAM-MD5] Dovecot (Debian) ready.
16:41:13.426 -> * CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ STARTTLS LOGINDISABLED AUTH=CRAM-MD5
16:41:13.426 -> $ OK Pre-login capabilities listed, post-login capabilities have more.
16:41:13.426 ->
16:41:13.426 -> Send command, STARTTLS
16:41:13.426 -> > send STARTTLS command
16:41:13.426 -> STARTTLS BAD Error in IMAP command received by server.
16:41:43.265 -> Error, connection closed
16:41:43.265 -> > E: connection closed

Additional information and things you've tried:

SSL works great.

our emailserver setup is after this tutorial
https://workaround.org/ispmail/bullseye/

always true tests and infinite loops

Builds using the ESP_Mail_Client library get 4 warnings for "comparison of unsigned expression >= 0 is always true" in ESP_Mail_Client.h (lines 1863. These are all from lines like:

for (size_t i = _«something».size() - 1; i >= 0; i--)

Since size_t is an unsigned datatype, 0 - 1 gives a positive result, and the i >= 0 test never fails. That looks like an infinite loop problem. I have not yet noticed a frozen system, so it appears none of my code has actually executed those blocks of code.

If you want to stick with size_t, those could be changed to:

for (size_t i = _«something».size(); i >= 1; i--)

or

for (size_t i = _«something».size(); i > 0; i--)

and use i - 1 in the loops instead of i.

or (if processing order does not matter)

for (size_t i = 0; i < _«something».size(); i++)

Otherwise, replaced size_t with a sufficient size signed datatype.

The raw source code:

  /** Clear all the inline images
  */
  void clearInlineimages()
  {
    for (size_t i = _att.size() - 1; i >= 0; i--)
    {
      if (_att[i]._int.att_type == esp_mail_att_type_inline)
        _att.erase(_att.begin() + i);
    }
  };

  /* Clear all the attachments */
  void clearAttachments()
  {
    for (size_t i = _att.size() - 1; i >= 0; i--)
    {
      if (_att[i]._int.att_type == esp_mail_att_type_attachment)
        _att.erase(_att.begin() + i);
    }

    for (size_t i = _parallel.size() - 1; i >= 0; i--)
      _parallel.erase(_parallel.begin() + i);
  };

  /** Clear all rfc822 message attachment
  */
  void clearRFC822Messages()
  {
    for (size_t i = _rfc822.size() - 1; i >= 0; i--)
    {
      _rfc822[i].clear();
      _rfc822.erase(_rfc822.begin() + i);
    }
  };

No auth SMTP can't connect

Is there a way to disable auth to use this with an unauthenticated internal SMTP relay? Not seeing an option for that, and it's not working.

README config value typo

Build tool used:

  • [X ] Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • [X ] ESP8266-based
  • ESP32-based

Other Libraries That are used:

n/a

Description of problem:
The Function definition README (https://github.com/mobizt/ESP-Mail-Client/blob/master/src/README.md) has the same description for 'attachment_size' limit config value and ' imap_idle_timeout'. Unless I'm mistaken, imap_idle_timeout is not related to attachment size, and the other text (circled red below) should be the description instead.

For context I was looking to understand the behavior of the 'listen' function to confirm if it implemented IMAP's Idle command (and by extension confirm I had found the right way to avoid hammering Office365 with polling, which I do believe this function correctly avoids doing. )

Share code snippet to reproduce the issue:
Screenshot of the readme page with the identical value descriptions highlighted
image

Additional information and things you've tried:
Thanks for this great library and examples!

Reboots on debug level 0

If i send email from an esp with wifi connection to router, everything is okay, but if i try it with an ethernet enabled esp32, it crashes with the following backtrace:

Connecting to SMTP server...
Guru Meditation Error: Core  1 panic'ed (InstrFetchProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x00000000  PS      : 0x00060530  A0      : 0x800fc8c5  A1      : 0x3ffb1aa0       
A2      : 0x3ffd81c4  A3      : 0x00000000  A4      : 0x3f405856  A5      : 0x0000001e  
A6      : 0xffffffff  A7      : 0xff000000  A8      : 0x800fc860  A9      : 0x3ffb1a90       
A10     : 0x3ffd81c4  A11     : 0x3f40586b  A12     : 0x000000ff  A13     : 0x0000ff00  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x00000004  EXCCAUSE: 0x00000014       
EXCVADDR: 0x00000000  LBEG    : 0x4008d5dd  LEND    : 0x4008d5ed  LCOUNT  : 0xffffffec  

ELF file SHA256: 0000000000000000

Backtrace: 0x00000000:0x3ffb1aa0 0x400fc8c2:0x3ffb1ac0 0x400fc146:0x3ffb1b20 0x400fc34c:0x3ffb1b70 0x400fbcec:0x3ffb1b90 0x400f6f9e:0x3ffb1bb0 0x400f8ddd:0x3ffb1c60 0x400e466d:0x3ffb1c90 0x400e4ad3:0x3ffb1e80 0x400e5f95:0x3ffb1f00 0x4010cfa0:0x3ffb1fb0 0x4008f566:0x3ffb1fd0
  #0  0x00000000:0x3ffb1aa0 in ?? ??:0
  #1  0x400fc8c2:0x3ffb1ac0 in esp_mail_ssl_client32::start_socket(esp_mail_ssl_client32::esp_mail_ssl_ctx32*, char const*, unsigned int, int, char const*, char const*, char const*, char const*, char const*, bool) at lib\ESP-Mail-Client-master\src\wcs\esp32/esp_mail_ssl_client32.cpp:594
  #2  0x400fc146:0x3ffb1b20 in ESP_Mail_WCS32::connect(char const*, unsigned short, char const*, char const*, char const*) at lib\ESP-Mail-Client-master\src\wcs\esp32/ESP_Mail_WCS32.cpp:457
  #3  0x400fc34c:0x3ffb1b70 in ESP_Mail_WCS32::connect(char const*, unsigned short) at lib\ESP-Mail-Client-master\src\wcs\esp32/ESP_Mail_WCS32.cpp:457
  #4  0x400fbcec:0x3ffb1b90 in ESP_Mail_HTTPClient32::connect(bool) at lib\ESP-Mail-Client-master\src\wcs\esp32/ESP_Mail_HTTPClient32.cpp:148
  #5  0x400f6f9e:0x3ffb1bb0 in ESP_Mail_Client::smtpAuth(SMTPSession*) at c:\users\pc\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\5.2.0\bits/vector.tcc:101      
  #6  0x400f8ddd:0x3ffb1c60 in SMTPSession::connect(esp_mail_session_config_t*) at c:\users\pc\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\5.2.0\bits/vector.tcc:101
  #7  0x400e466d:0x3ffb1c90 in sendEmail(String, String, String, String) at src/Own_Headers/ModBus.h:365 (discriminator 2)
  #8  0x400e4ad3:0x3ffb1e80 in sendRestartEmail() at src/Own_Headers/ModBus.h:365 (discriminator 2)
  #9  0x400e5f95:0x3ffb1f00 in loop() at src/Own_Headers/ModBus.h:365 (discriminator 2)      
  #10 0x4010cfa0:0x3ffb1fb0 in loopTask(void*) at C:\Users\Pc\.platformio\packages\framework-arduinoespressif32\cores\esp32/main.cpp:23
  #11 0x4008f566:0x3ffb1fd0 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)

I'am using LAN8720 eth chip with the ETH library from espressif.

Email sender function is looks like this

String MAINTAINER_NAME  = "Dr.Random";
String MAINTAINER_EMAIL  = "email is good";
String MAINTAINER_PASS    = "password is good.";
String GOOGLE_SMTP_HOST = "smtp.gmail.com";
#define GOOGLE_SMTP_PORT 465
#define RESTART_EMAIL_TIME 30000

SMTPSession smtp;
void smtpCallback(SMTP_Status status);

const inline boolean sendEmail(String sub,String msg,String emailTo,String nameTo){
    if(ETH_Got_IP){
        smtp.debug(0);
        smtp.callback(smtpCallback);
        ESP_Mail_Session session;

        session.server.host_name    = GOOGLE_SMTP_HOST.c_str();
        session.server.port         = GOOGLE_SMTP_PORT;
        session.login.email         = MAINTAINER_EMAIL.c_str();
        session.login.password      = MAINTAINER_PASS.c_str();

        SMTP_Message message;
        message.sender.name     = MAINTAINER_NAME.c_str();
        message.sender.email    = MAINTAINER_EMAIL.c_str();
        message.subject         = sub.c_str();
        message.addRecipient(nameTo.c_str(), emailTo.c_str());
        message.text.flowed     = true;
        message.text.content    = msg.c_str();
        message.text.charSet    = "us-ascii";

        message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
        message.priority        = esp_mail_smtp_priority::esp_mail_smtp_priority_low;
        message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay;

        if (!smtp.connect(&session)){
            errorLog("Can't estabilish email session...");
            return false;
        }

        if (!MailClient.sendMail(&smtp, &message)){
            errorLog("Error sending Email, " + smtp.errorReason());
            return false;
        }

        return true;
    }
    return false;
}

can't add Recipient from string variavle

Hi.
Im trying to add names and emails from an array, but i always get: "error sending Email, some of the recipient Email address is not valid", but i know for sure that the contents of the string variable are rigth. Sorry my English is very poor. Please Help :)

int i=0;

while(i<10){
String tempNomes = NOMES[i] ;
String tempMails = MAILS[i]';

if(tempMails.length()>5){
message.addRecipient(&tempNomes[0],&tempMails[0]);
}

i++;

}

5.5.4 Error: Bad NOTIFY parameter syntax

Build tool used:

  • Arudino
  • [ X ] Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32):

  • ESP8266-based
  • ESP32-based

Other Libraries That are used:

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_port = /dev/ttyUSB0
monitor_speed = 115200
upload_port = /dev/ttyUSB0
upload_speed = 115200
lib_deps =
openenergymonitor/EmonLib@^1.1.0
mobizt/ESP Mail Client@^1.3.2

Description of problem:
Hi dear,
I try to send e-mail to my postifx, but I receveid the follow error:
< S: 250-mail.rclabs.com.br
< S: 250-PIPELINING
< S: 250-SIZE 10240000
< S: 250-ETRN
< S: 250-AUTH PLAIN LOGIN
< S: 250-AUTH=PLAIN LOGIN
< S: 250-ENHANCEDSTATUSCODES
< S: 250-8BITMIME
< S: 250-DSN
< S: 250 SMTPUTF8

C: send smtp command, AUTH PLAIN
C: rcosta
C: rcosta ************
< S: 235 2.7.0 Authentication successful
C: send Email
C: send message header
< S: 250 2.1.0 Ok
< S: 501 5.5.4 Error: Bad NOTIFY parameter syntax
E: set recipient failed
C: cleaning SSL connection
Error sending Email, set recipient failed

Share code snippet to reproduce the issue:

PASTE .cpp / .ino code here
Relevant parto of the code:
 smtp.debug(1);
  smtp.callback(smtpCallback);

  ESP_Mail_Session session;
  session.server.host_name = "xpto.rclabs.com.br";
  session.server.port = 587;
  session.login.email = "rcosta";
  session.login.password = "xpto";
  session.login.user_domain = "";

  SMTP_Message message;
  message.sender.name = "Xpto From";
  message.sender.email = "<[email protected]>";
  message.subject = "Falta de energia";
  message.addRecipient("Xpto To", "<[email protected]>");

Additional information and things you've tried:
I try to remove "<" and ">" in the e-mail address, but occurs the same error.

message body is not downloaded

Build tool used:

  • Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • ESP32-based

Other Libraries That are used:

none

Description of problem:
I tried your example code "Read_Single_Email.ino" with only one minor modification: search criteria were set to "not seen" (config.search.criteria = "UID SEARCH NOT SEEN";); this is probably not relevant in this issue.

The sketch finds the one unseen message in my inbox, fetches the subject of the mail, prints it out correctly BUT does not fetch/print the text message of the mail body. The status of the mail is left "not seen".

So my questions are:
How can I fetch/print the body of the mail?
How can I set the status to "seen" after fetching it?

Share code snippet to reproduce the issue:

PASTE .cpp / .ino code here

Additional information and things you've tried:
This ist the printout from the arduino console:

14:16:00.521 -> Message fetch cmpleted
14:16:00.521 -> > C: message fetch completed
14:16:00.521 -> > C: cleaning SSL connection
14:16:00.521 ->
14:16:00.521 -> ################################
14:16:00.521 -> Messsage Number: 1
14:16:00.521 -> Messsage UID: 1902
14:16:00.521 -> Messsage ID: 1345373619.101.1627808201421@localhost
14:16:00.521 -> Accept Language:
14:16:00.521 -> Content Language:
14:16:00.521 -> From: NAKIVO Backup & Replication [email protected]
14:16:00.521 -> From Charset:
14:16:00.521 -> To: [email protected]
14:16:00.521 -> To Charset:
14:16:00.521 -> CC:
14:16:00.521 -> CC Charset:
14:16:00.521 -> Date: Sun, 1 Aug 2021 10:56:41 +0200 (CEST)
14:16:00.521 -> Subject: You have 1 new alarm
14:16:00.521 -> Subject Charset:
14:16:00.521 -> Text Message:
14:16:00.521 -> Text Message Charset:
14:16:00.521 -> Text Message Transfer Encoding:
14:16:00.521 -> HTML Message:
14:16:00.521 -> HTML Message Charset: UTF-8
14:16:00.521 -> HTML Message Transfer Encoding: 7bit

Header Parsing Problem?

Hi mobizt,
I'm not sure if I'm missing something, but when receiving messages via IMAP, I can't get any properties populated apart from msg.msgNo and msg.UID. I tried using an ESP32 and ESP8266 (Wemos D1 Mini) with the Read_Single_Email example and library Version 1.0.8. Interestingly debug (333) outputs all the properties (see console output below). With your old library (ESP32-Mail-Client) I am able to access all the properties, but I would like to use the new library. Any help would be greatly appreciated.

Kind regards

Dkalliv

Connecting to IMAP server...

C: ESP Mail Client v1.0.8
C: connect to IMAP server
C: host > imap.swizzonic-mail.ch
C: port > 993
C: starting socket
C: connecting to Server
C: seeding the random number generator
C: setting up the SSL/TLS structure
C: setting hostname for TLS session
C: performing the SSL handshaking
C: verifying peer X.509 certificate
C: certificate verified
IMAP server connected
C: server connected

Get the capability...

C: get the capability
$ CAPABILITY

  • OK swizzonic-mail.ch CommuniGate Pro IMAP Server 6.2.15 ready
  • CAPABILITY IMAP4 IMAP4REV1 ACL NAMESPACE UIDPLUS IDLE LITERAL+ QUOTA ID MULTIAPPEND LISTEXT CHILDREN BINARY ESEARCH LOGIN-REFERRALS UNSELECT SASL-IR LIST-EXTENDED SPECIAL-USE CREATE-SPECIAL-USE XLIST AUTH=LOGIN AUTH=PLAIN
    $ OK completed

Logging in...

C: send imap command, LOGIN
$ LOGIN [email protected] *********
$ OK completed

Reading the list of mailboxes...

C: send imap command, LIST
$ LIST "" *

  • LIST (\HasNoChildren \Marked) "/" INBOX
    $ OK completed

Available folders: INBOX

Selecting the INBOX folder...

C: open the mailbox folder
$ EXAMINE "INBOX"

  • FLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Hidden $Media $Forwarded Junk $Label1 $Label2 $Label3)
  • OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Hidden $Media $Forwarded Junk $Label1 $Label2 $Label3)] limited
  • 5 EXISTS
  • 5 RECENT
  • OK [UIDNEXT 6] predicted next UID
  • OK [UIDVALIDITY 402276210] UIDs valid
  • OK [UNSEEN 1] message 1 is first unseen
    $ OK [READ-ONLY] EXAMINE completed

Info of the selected folder
Total Messages: 5
Predicted next UID: 6
Flags: \Answered, \Flagged, \Deleted, \Seen, \Draft, $MDNSent, $Hidden, $Media, $Forwarded, Junk, $Label1, $Label2, $Label3

Fetching message 1, UID: 5

C: send imap command, FETCH
C: fetch message header
$ UID FETCH 5 BODY.PEEK[HEADER.FIELDS (SUBJECT FROM TO DATE CC Message-ID Accept-Language content-type Content-transfer-encoding Content-Language)]

  • 5 FETCH (BODY[HEADER.FIELDS ("SUBJECT" "FROM" "TO" "DATE" "CC" "Message-ID" "Accept-Language" "content-type" "Content-transfer-encoding" "Content-Language")] {282}
    Subject: test 5
    From: [email protected]
    To: "[email protected]" [email protected]
    Date: Sun, 27 Dec 2020 22:42:28 +0100
    Message-ID: [email protected]
    Content-Type: text/plain; charset="utf-8"; format="flowed"
    Content-Transfer-Encoding: 8bit
    UID 5)
    $ OK completed

C: fetch body part header, 1
$ UID FETCH 5 BODY.PEEK[header.fields (content-type Content-transfer-encoding)]

  • 5 FETCH (BODY[header.fields ("content-type" "Content-transfer-encoding")] {95}
    Content-Type: text/plain; charset="utf-8"; format="flowed"
    Content-Transfer-Encoding: 8bit
    UID 5)
    $ OK completed

Downloading messages...

C: download plain TEXT message
$ UID FETCH 5 BODY.PEEK[TEXT]
download /email_data/5/msg.txt, 100%
$ OK completed

Saving message header to file...

C: Free Heap: 217404

Logging out...

C: send imap command, LOGOUT
$ LOGOUT

  • BYE CommuniGate Pro IMAP Server closing connection
    $ OK completed
    ! E: SSL - The peer notified us that the connection is going to be closed

C: cleaning SSL connection

Message fetch cmpleted

C: message fetch completed

################################
Messsage Number: 1
Messsage UID: 5
Messsage ID:
Accept Language:
Content Language:
From:
From Charset:
To:
To Charset:
CC:
CC Charset:
Date:
Subject:
Subject Charset:
Text Message: tst
Text Message Charset: utf-8
Text Message Transfer Encoding: 8bit
HTML Message:
HTML Message Charset:
HTML Message Transfer Encoding:

Free Heap: 260020

Fetch messages

Hi
I got the error
Fetching message 1, UID: 100

C: send imap command, FETCH
C: fetch message header
$ UID FETCH 100 BODY.PEEK[HEADER.FIELDS (SUBJECT FROM TO DATE CC Message-ID Accept-Language content-type Content-transfer-encoding Content-Language)]
$ OK Success
Error, some of the requested messages no longer exist
E: some of the requested messages no longer exist

Can you help me?
Thanks
Juergen

setFlag still not working?

Hello,
I replaced the previous library with version 1.0.8. Unfortunately, upon attempting to verify the Set_Flag example, I encounter the following:

Set_Flags:202:65: error: no matching function for call to 'ESP_Mail_Client::setFlag(IMAPSession&, int, const char [16], bool)'
if (MailClient.setFlag(imap, 100, "\Seen \Answered", false))

Not sure if I'm doing something incorrectly...
thank you.

debug print shows date/time always back to the past

hi, it is possible an issue or no update to the log only, how is date/time info obtained, depends on SMTP server or the ESP device ? I was used the gmail for testing, could we uses this time/date info for other purpose ? or really need RTC chip to work with ESP device together ?
date_alway_the_same

Bulk deletion?

Build tool used:

  • Arduino

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based

Other Libraries That are used:

Description of problem:

Hi, I am a new user of this library. I am trying to find a way to delete all email in the inbox whenever it is checked. I have tried to use the Delete_Messsages example by creating a MessageList containing as many UID as possible, but it seems there's a limit to that. I noticed that the UID of new email will keep increasing even if the previous email have been deleted, but I can't create an infinite MessageList. May I ask how I can solve this? Is there a command of bulk deletion or resetting the MessageList?


**Additional information and things you've tried:**




<!-- LEAVE THIS LINE AS-IS AND DON'T DELETE IT, OTHERWISE THE ISSUE WILL BE CLOSED AUTOMATICALLY. -->

when set “config.search.criteria” ,then can't receive attachment

Build tool used:

  • Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • ESP32-based

Other Libraries That are used:

Description of problem:
I used v1.5.3 and example “Read_single_Email” for test.
If set "config.search.criteria =""" or "config.fetch.uid = uid.c_str();" ,it can receive attachment .
but when I set like this:
config.search.criteria = "UID SEARCH ALL";
//config.fetch.uid = uid.c_str();
then can't receive attachment.

Share code snippet to reproduce the issue:

 /* Setup the configuration for searching or fetching operation and its result */
    IMAP_Config config;

    /* Set seen flag */
    //config.fetch.set_seen = true;

    /* Search criteria */
    config.search.criteria = "UID SEARCH ALL";

    /* Also search the unseen message */
    config.search.unseen_msg = true;

    /* Set the storage to save the downloaded files and attachments */
    config.storage.saved_path = "/email_data";

    /** The file storage type e.g.
     * esp_mail_file_storage_type_none,
     * esp_mail_file_storage_type_flash, and 
     * esp_mail_file_storage_type_sd 
    */
    config.storage.type = esp_mail_file_storage_type_flash;

    /** Set to download heades, text and html messaeges, 
     * attachments and inline images respectively.
    */
    config.download.header = true;
    config.download.text = true;
    config.download.html = true;
    config.download.attachment = true;
    config.download.inlineImg = true;

    /** Set to enable the results i.e. html and text messaeges 
     * which the content stored in the IMAPSession object is limited
     * by the option config.limit.msg_size.
     * The whole message can be download through config.download.text
     * or config.download.html which not depends on these enable options.
    */
    config.enable.html = true;
    config.enable.text = true;

    /* Set to enable the sort the result by message UID in the ascending order */
    config.enable.recent_sort = true;

    /* Set to report the download progress via the default serial port */
    config.enable.download_status = true;

    /* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud
    , to allow case sensitive parse, uncomment below line*/
    //config.enable.header_case_sensitive = true;

    /* Set the limit of number of messages in the search results */
    config.limit.search = 5;

    /** Set the maximum size of message stored in 
     * IMAPSession object in byte
    */
    config.limit.msg_size = 512;

    /** Set the maximum attachments and inline images files size
     * that can be downloaded in byte. 
     * The file which its size is largger than this limit may be saved 
     * as truncated file.
    */
    config.limit.attachment_size = 1024 * 1024 * 5;


    /* Connect to server with the session and config */
    if (!imap.connect(&session, &config))
        return;

    /*  {Optional} */
    printAllMailboxesInfo(imap);

    /* Open or select the mailbox folder to read or search the message */
    if (!imap.selectFolder("INBOX"))
        return;

    /*  {Optional} */
    printSelectedMailboxInfo(imap.selectedFolder());

    /** Message UID to fetch or read e.g. 100. 
     * In this case we will get the UID from the max message number (lastest message) 
    */
    String uid = String(imap.getUID(imap.selectedFolder().msgCount()));
    //config.fetch.uid = uid.c_str();

    /* Read or search the Email and close the session */

    //When message was fetched or read, the /Seen flag will not set or message remained in unseen or unread status,
    //as this is the purpose of library (not UI application), user can set the message status as read by set \Seen flag
    //to message, see the Set_Flags.ino example.
    MailClient.readMail(&imap);

    /* Clear all stored data in IMAPSession object */
    imap.empty();
}

void loop()
{

}

/* Callback function to get the Email reading status */
void imapCallback(IMAP_Status status)
{
    /* Print the current status */
    Serial.println(status.info());

    /* Show the result when reading finished */
    if (status.success())
    {
        /* Print the result */
        /* Get the message list from the message list data */
        IMAP_MSG_List msgList = imap.data();
        printMessages(msgList.msgItems, imap.headerOnly());

        /* Clear all stored data in IMAPSession object */
        imap.empty();
    }
}

void printAllMailboxesInfo(IMAPSession &imap)
{
    /* Declare the folder collection class to get the list of mailbox folders */
    FoldersCollection folders;

    /* Get the mailbox folders */
    if (imap.getFolders(folders))
    {
        for (size_t i = 0; i < folders.size(); i++)
        {
            /* Iterate each folder info using the  folder info item data */
            FolderInfo folderInfo = folders.info(i);
            ESP_MAIL_PRINTF("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : "");
        }
    }
}

void printSelectedMailboxInfo(SelectedFolderInfo sFolder)
{
    /* Show the mailbox info */
    ESP_MAIL_PRINTF("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount());
    ESP_MAIL_PRINTF("Predicted next UID: %d\n", sFolder.nextUID());
    for (size_t i = 0; i < sFolder.flagCount(); i++)
        ESP_MAIL_PRINTF("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : "");
}

void printAttacements(std::vector<IMAP_Attach_Item> &atts)
{
    ESP_MAIL_PRINTF("Attachment: %d file(s)\n****************************\n", atts.size());
    for (size_t j = 0; j < atts.size(); j++)
    {
        IMAP_Attach_Item att = atts[j];
        /** att.type can be
         * esp_mail_att_type_none or 0
         * esp_mail_att_type_attachment or 1
         * esp_mail_att_type_inline or 2
        */
        ESP_MAIL_PRINTF("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.creationDate);
    }
    Serial.println();
}

void printMessages(std::vector<IMAP_MSG_Item> &msgItems, bool headerOnly)
{

    for (size_t i = 0; i < msgItems.size(); i++)
    {

        /* Iterate to get each message data through the message item data */
        IMAP_MSG_Item msg = msgItems[i];

        Serial.println("****************************");
        ESP_MAIL_PRINTF("Number: %d\n", msg.msgNo);
        ESP_MAIL_PRINTF("UID: %d\n", msg.UID);
        ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

        ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);

        ESP_MAIL_PRINTF("Attachment: %s\n", msg.hasAttachment ? "yes" : "no");

        if (strlen(msg.acceptLang))
            ESP_MAIL_PRINTF("Accept Language: %s\n", msg.acceptLang);
        if (strlen(msg.contentLang))
            ESP_MAIL_PRINTF("Content Language: %s\n", msg.contentLang);
        if (strlen(msg.from))
            ESP_MAIL_PRINTF("From: %s\n", msg.from);
        if (strlen(msg.sender))
            ESP_MAIL_PRINTF("Sender: %s\n", msg.sender);
        if (strlen(msg.to))
            ESP_MAIL_PRINTF("To: %s\n", msg.to);
        if (strlen(msg.cc))
            ESP_MAIL_PRINTF("CC: %s\n", msg.cc);
        if (strlen(msg.date))
            ESP_MAIL_PRINTF("Date: %s\n", msg.date);
        if (strlen(msg.subject))
            ESP_MAIL_PRINTF("Subject: %s\n", msg.subject);
        if (strlen(msg.reply_to))
            ESP_MAIL_PRINTF("Reply-To: %s\n", msg.reply_to);
        if (strlen(msg.return_path))
            ESP_MAIL_PRINTF("Return-Path: %s\n", msg.return_path);
        if (strlen(msg.in_reply_to))
            ESP_MAIL_PRINTF("In-Reply-To: %s\n", msg.in_reply_to);
        if (strlen(msg.references))
            ESP_MAIL_PRINTF("References: %s\n", msg.references);
        if (strlen(msg.comments))
            ESP_MAIL_PRINTF("Comments: %s\n", msg.comments);
        if (strlen(msg.keywords))
            ESP_MAIL_PRINTF("Keywords: %s\n", msg.keywords);

        /* If the result contains the message info (Fetch mode) */
        if (!headerOnly)
        {
            if (strlen(msg.text.content))
                ESP_MAIL_PRINTF("Text Message: %s\n", msg.text.content);
            if (strlen(msg.text.charSet))
                ESP_MAIL_PRINTF("Text Message Charset: %s\n", msg.text.charSet);
            if (strlen(msg.text.transfer_encoding))
                ESP_MAIL_PRINTF("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding);
            if (strlen(msg.html.content))
                ESP_MAIL_PRINTF("HTML Message: %s\n", msg.html.content);
            if (strlen(msg.html.charSet))
                ESP_MAIL_PRINTF("HTML Message Charset: %s\n", msg.html.charSet);
            if (strlen(msg.html.transfer_encoding))
                ESP_MAIL_PRINTF("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding);

            if (msg.rfc822.size() > 0)
            {
                ESP_MAIL_PRINTF("RFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size());
                printMessages(msg.rfc822, headerOnly);
            }
        }

        Serial.println();
    }
}

Additional information and things you've tried:
.......
WiFi connected.
IP address:
192.168.8.164

Connecting to IMAP server...

C: ESP Mail Client v1.5.3
C: connect to IMAP server
C: host > outlook.office365.com
C: port > 993
C: starting socket
C: connecting to Server
C: seeding the random number generator
C: setting up the SSL/TLS structure
! W: Skipping SSL Verification. INSECURE!
C: setting hostname for TLS session
C: performing the SSL/TLS handshake
C: verifying peer X.509 certificate
IMAP server connected
C: server connected

Check the capability...

C: check the capability

Logging in...

C: send imap command, LOGIN

Reading the list of mailboxes...

C: send imap command, LIST

Available folders: Notes, Drafts, &W1hoYw-, Outbox, Junk, Inbox, Sent, Deleted

Selecting the INBOX folder...

C: open the mailbox folder

Info of the selected folder
Total Messages: 2
Predicted next UID: 112
Flags: \Seen, \Answered, \Flagged, \Deleted, \Draft, $MDNSent
Get UID...

C: get UID...
UID is 110
C: UID is 110

Searching messages...

C: search messages
C: 100%

Search limit:5
Found 2 messages
Show 2 messages

Fetching message 1, UID: 110

C: send imap command, FETCH
C: fetch message header
Get Flags...
C: get flags...
C: Free Heap: 231512

Fetching message 2, UID: 108

C: send imap command, FETCH
C: fetch message header
Get Flags...
C: get flags...
C: Free Heap: 230496
Logging out...
C: send imap command, LOGOUT

Message fetch cmpleted

C: message fetch completed
C: cleaning SSL connection


Number: 2
UID: 110
Messsage-ID: OSZP286MB16786EA0F49480F46CFE5B91C9A89@OSZP286MB1678.JPNP286.PROD.OUTLOOK.COM
Flags: \Recent
Attachment: yes
From: ESP Mail[email protected]
To: user1[email protected]
Date: Tue, 28 Sep 2021 00:57:05 +0000
Subject: happy test
Return-Path: [email protected]


Number: 1
UID: 108
Messsage-ID: OSZP286MB1678FE9D684C8947CF7EA04DC9A89@OSZP286MB1678.JPNP286.PROD.OUTLOOK.COM
Flags: \Recent
Attachment: yes
From: ESP Mail[email protected]
To: user1[email protected]
Date: Tue, 28 Sep 2021 00:53:04 +0000
Subject: Test sending Email with parallel attachments
Return-Path: [email protected]

Build error when Debug Level is set to SSL+HTTP_CLIENT

Build tool used:

  • Arduino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • ESP32-based

Other Libraries That are used:

None for the minimum sketch.

Description of problem:

Build error when Debug Level is set to SSL+HTTP_CLIENT.

arduino/libraries/ESP_Mail_Client/src/wcs/esp8266/ESP8266_WCS.cpp: In member function 'virtual int ESP8266_WCS::connect(const char*, uint16_t)':
arduino/libraries/ESP_Mail_Client/src/wcs/esp8266/ESP8266_WCS.cpp:59:30: error: 'DEBUG_ESP_PORT' was not declared in this scope; did you mean 'DEBUG_ESP_SSL'?
   59 | #define DEBUG_BSSL(fmt, ...) DEBUG_ESP_PORT.printf_P((PGM_P)PSTR("BSSL:" fmt), ##__VA_ARGS__)
      |                              ^~~~~~~~~~~~~~
arduino/libraries/ESP_Mail_Client/src/wcs/esp8266/ESP8266_WCS.cpp:79:5: note: in expansion of macro 'DEBUG_BSSL'
   79 |     DEBUG_BSSL("connect: Name loopup failure\n");
      |     ^~~~~~~~~~
arduino/libraries/ESP_Mail_Client/src/wcs/esp8266/ESP8266_WCS.cpp:59:30: error: 'DEBUG_ESP_PORT' was not declared in this scope; did you mean 'DEBUG_ESP_SSL'?
   59 | #define DEBUG_BSSL(fmt, ...) DEBUG_ESP_PORT.printf_P((PGM_P)PSTR("BSSL:" fmt), ##__VA_ARGS__)
      |                              ^~~~~~~~~~~~~~
arduino/libraries/ESP_Mail_Client/src/wcs/esp8266/ESP8266_WCS.cpp:85:5: note: in expansion of macro 'DEBUG_BSSL'
   85 |     DEBUG_BSSL("connect: Unable to connect TCP socket\n");
      |     ^~~~~~~~~~

Code snippet to reproduce the issue:

#include <ESP_Mail_Client.h>
void setup() {}
void loop() {}

Additional information and things you've tried:
N/A

"Outside Heap area error" when I give command to send email again through POST request from Webserver

Build tool used:

  • [ X] Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • [X ] ESP32-based

Other Libraries That are used:

**Description of problem: **
I made an HTML page hosted on ESP32 Webserver. On the HTML page there are 5 inputs fields generated dinamically where the user fills in 5 email. When user clicks on submit button a POST request is made to the server and with EEPROM library I save the email on ESP32 memory and I use ESP-Mail-Client to send a welcome mail to all emails. I made a function to send the emails. I have used the Send_Text.ino example. But it work only once. If on the client side they click the button again to send another email there is heap error. If I reset the ESP32 it works but not two times or more in a row. See image below for the interface.
image

The first time I press the 'save' button the email is sent but the second time I press it I get this error. I am sure that is not related to EEPROM saving email as that prints out ok.

assertion "heap != NULL && "free() target pointer is outside heap areas"" failed: file "IDF/components/heap/heap_caps.c", line 304, function: heap_caps_free
abort() was called at PC 0x401956c3 on core 1 

Share code snippet to reproduce the issue:

//function that give true if email was sent correctly or false if not. I pass to the function two strings: emailSubject and emailText
//I copied this funciton from your example
bool sendEmail(String emailSubject, String emailText){

  smtp.debug(1);   //put to 0 to remove email debug messages
  smtp.callback(smtpCallback);
  
  ESP_Mail_Session session;
 
  session.server.host_name = SMTP_HOST;
  session.server.port = SMTP_PORT;
  session.login.email = AUTHOR_EMAIL;
  session.login.password = AUTHOR_PASSWORD;
  session.login.user_domain = "example.com"; 
  
  getEmail(); //with this function I get the email1, email2 etc. from EEPROM
  
  SMTP_Message message;
  message.sender.name = "Name";
  message.sender.email = AUTHOR_EMAIL;
  message.subject = emailSubject.c_str();     //it needs to be a constant char so I convert it to c_str()
  if (email1!=""){message.addRecipient("user1", email1.c_str());}
  if (email2!=""){message.addRecipient("user1", email2.c_str());}
  if (email3!=""){message.addRecipient("user1", email3.c_str());}
  if (email4!=""){message.addRecipient("user1", email4.c_str());}
  if (email5!=""){message.addRecipient("user1", email5.c_str());}
  message.addBcc(AUTHOR_EMAIL); 
  message.text.content = emailText.c_str();
  
  message.text.charSet = "us-ascii";
  message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
  message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_high;

  session.certificate.cert_data = rootCACert;
  session.certificate.verify = true;
  if (!smtp.connect(&session)){    
    return false;
  }
  if (!MailClient.sendMail(&smtp, &message)){
    Serial.println("Error sending Email, " + smtp.errorReason());  
    return false;
  } else {
 
    Serial.println("FREE HEAP");
    Serial.print(MailClient.getFreeHeap());
    Serial.print("Bytes");

    return true;
  }
}

//also this funtion is copied
void smtpCallback(SMTP_Status status)
{
  /* Print the current status */
  Serial.println(status.info());

  /* Print the sending result */
  if (status.success())
  {
    Serial.println("----------------");
    ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount());
    ESP_MAIL_PRINTF("Message sent failled: %d\n", status.failedCount());
    Serial.println("----------------\n");
    struct tm dt;

    for (size_t i = 0; i < smtp.sendingResult.size(); i++)
    {
      /* Get the result item */
      SMTP_Result result = smtp.sendingResult.getItem(i);
      time_t ts = (time_t)result.timestamp;
      localtime_r(&ts, &dt);

      ESP_MAIL_PRINTF("Message No: %d\n", i + 1);
      ESP_MAIL_PRINTF("Status: %s\n", result.completed ? "success" : "failed");
      ESP_MAIL_PRINTF("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec);
      ESP_MAIL_PRINTF("Recipient: %s\n", result.recipients);
      ESP_MAIL_PRINTF("Subject: %s\n", result.subject);
    }
    Serial.println("----------------\n"); 
    smtp.sendingResult.clear();    //I have added this line to clear results 
  }
}

void handleRequest(){
if (server.hasArg("email1")||server.hasArg("email2")||server.hasArg("email3")||server.hasArg("email4")||server.hasArg("email5")) {
    Serial.println("email request arrived");
    handleEmail();
  }
}

//this funciton save email in EEPROM and then send email
void handleEmail(){
  for(int i=1; i<6; i++){  
  Serial.println("received email by request");
  Serial.println(server.arg("email"+String(i)+"")); //if the POST value is empty it will receive an empty string
  String email0=server.arg("email"+String(i)+"");
  wrStrToMem(email0, 65, (75+i+((i-1)*65)));    //this function pass to the EEPROM the email saved in the right addresses
  }

//if wifi is connected and email is send successful respond with success message to the client
if((checkConnection()==true)&&(sendEmail(emailSubject, emailText)==true)){
    String response_success="all good, email sent, if you have not received it please make sure it is not in the spam folder or that you typed the address correctly";
    server.send(200, "text/html", response_success);
}

Additional information and things you've tried:

I have added smtp.sendingResult.clear();
but nothing changed

I beleive I need to cancel / flush some parameters that saturate my heap.
I tried adding
smtp.closeSession();
message.clear();
I also wanted to use the empty() method but as MailClient.empty(); or smtp.empty(); but it didn't work

I start to think that there is incompability between #include <WebServer.h> and #include <ESP_Mail_Client.h>

NTP server timeout - Error, NTP server time synching timed out

Build tool used:

  • Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other
    PROGRAMINO IDE

Board used (ESP32/ESP8266/Arudino):

Other Libraries That are used:

#include <Arduino.h>
#include <string.h>
#include <FS.h>
#include <SD.h>
#include <SPIFFS.h>
#include <Update.h>
#include <SPI.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <WiFi.h>
#include <HTTPClient.h> // HTTP client I use for loging values to cloud.
#include <ESP32Ping.h>
#include <ESP_Mail_Client.h>
#include <EEPROM.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <axp20x.h> // Power management
#include <PCF8574.h> // Port expander

Description of problem:
After last actualisation always happens, that NTP server is not available or don't answer so quick, as is necessary. Here is report of Email client debug and callback:
On older library happens the same (what I remember) only one time.

Connecting to SMTP server...

C: ESP Mail Client v2.2.2
C: Wait for NTP server time synching
Error, NTP server time synching timed out
E: NTP server time synching timed out
C: Connect to SMTP server
C: Host > smtp.gmail.com
C: Port > 465
C: starting socket
C: connecting to Server
C: seeding the random number generator
C: setting up the SSL/TLS structure
! W: Skipping SSL Verification. INSECURE!
C: setting hostname for TLS session
C: performing the SSL/TLS handshake
C: verifying peer X.509 certificate
C: SMTP server connected
SMTP server connected, wait for greeting...
< S: 220 smtp.gmail.com ESMTP lv15-20020a170906bc8f00b006f3ef214dfcsm1904077ejb.98 - gsmtp
Sending greeting response...
C: Send SMTP command, HELO
< S: 250-smtp.gmail.com at your service, [85.71.29.47]
< S: 250-SIZE 35882577
< S: 250-8BITMIME
< S: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
< S: 250-ENHANCEDSTATUSCODES
< S: 250-PIPELINING
< S: 250-CHUNKING
< S: 250 SMTPUTF8
Logging in...
C: Send SMTP command, AUTH PLAIN
C: [email protected]
C: [email protected] ****************
< S: 235 2.7.0 Accepted
C: Send Email
Sending message header...
C: Send message header
< S: 250 2.1.0 OK lv15-20020a170906bc8f00b006f3ef214dfcsm1904077ejb.98 - gsmtp
< S: 250 2.1.5 OK lv15-20020a170906bc8f00b006f3ef214dfcsm1904077ejb.98 - gsmtp
Sending message body...
C: Send message body
< S: 354 Go ahead lv15-20020a170906bc8f00b006f3ef214dfcsm1904077ejb.98 - gsmtp
Finishing the message sending...
C: Finish the message sending
< S: 250 2.0.0 OK 1652351524 lv15-20020a170906bc8f00b006f3ef214dfcsm1904077ejb.98 - gsmtp
Closing the session...
C: Terminate the SMTP session
< S: 221 2.0.0 closing connection lv15-20020a170906bc8f00b006f3ef214dfcsm1904077ejb.98 - gsmtp
Message sent successfully
C: Message sent successfully
Sent: 1
C: cleaning SSL connection

Share code snippet to reproduce the issue:

PASTE .cpp / .ino code here

            if(PoradiSekvenceOdesliEmailWiFi == 0){
               String PredmetEmailu; //Subject of e-mail
               PocetOpakovaniPrikazuWiFi = 0; // Num of iteration of try send it
               OdeselPrikazDoWIFI        = true; // Locking variable to "No make something else with Wifi "(used in other part of program)
               // ------------------- PŘÍPRAVA ZPRÁVY ---------------------
               session.server.host_name  = AdresaSMTPServeru;
               session.server.port       = PortSMTPServeru;
               session.login.email       = EmailZarizeni;
               session.login.password    = HesloEmailZarizeni;
               session.login.user_domain = "";
               
               if(KodEmailu.substring(0,2) == "EN"){ // Setting of e-mail header and body depended on issue character
                  message.subject = PredmetEmailuNapajeni;
                  PredmetEmailu   = PredmetEmailuNapajeni;
                  TextEmailu      = TextEmailuNapajeni;
               }else if(KodEmailu.substring(0,2) == "EB"){
                  message.subject = PredmetEmailuBaterie;
                  PredmetEmailu   = PredmetEmailuBaterie;
                  TextEmailu      = TextEmailuBaterie;
               }else if(KodEmailu.substring(0,2) == "ET"){
                  message.subject = PredmetEmailuTeplota;
                  PredmetEmailu   = PredmetEmailuTeplota;
                  TextEmailu      = TextEmailuTeplota;
               }else if(KodEmailu.substring(0,2) == "ES"){
                  message.subject = PredmetEmailuKvalitaSignalu;
                  PredmetEmailu   = PredmetEmailuKvalitaSignalu;
                  TextEmailu      = TextEmailuKvalitaSignalu;
               }
               message.sender.name  = NazevZarizeniEmail;
               message.sender.email = EmailZarizeni;
               message.addRecipient("", EmailAdresata); 
               message.html.charSet = "utf-8";
               message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
               message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_high;
               message.response.notify = esp_mail_smtp_notify_never;
               TextEmailu = "<!DOCTYPE html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><meta http-equiv=\"Content-Transfer-Encoding\" encoding=\"quoted-printable\"><title>" + PredmetEmailu + "</title></head><body>" + TextEmailu + "</body></html>";
               message.html.content          = TextEmailu.c_str();
               PoradiSekvenceOdesliEmailWiFi = 1;
            }else if(PoradiSekvenceOdesliEmailWiFi == 1){
               if(PocetOpakovaniPrikazuWiFi > 2){
                  smtp.sendingResult.clear();
                  message.clear();
                  OdesliEmail                   = false;
                  OdeselPrikazDoWIFI            = false; // Unlocking WIFI next commands
                  PoradiSekvenceOdesliEmailWiFi = 0;
                  VyresHlaseniWIFIEmailem(4); // Routine for Logging of e-mail sending results (write numbers to byte array)
               }else{
                  ledcWrite(Kanal, 0);
                  if (!smtp.connect(&session)){
                     VyresHlaseniWIFIEmailem(4);
                     OdeselPrikazDoWIFI = false; // Unlocking WIFI next commands
                     if(smtp.closeSession() == true){
                     }else{
                     }
                     PoradiSekvenceOdesliEmailWiFi = 0;
                     PocetOpakovaniPrikazuWiFi     = 0;
                     message.clear();
                     smtp.sendingResult.clear();
                     PocetOpakovaniPrikazuWiFi++;
                  }else{
                     VyresHlaseniWIFIEmailem(1);
                     ledcWrite(Kanal, 0);
                     PoradiSekvenceOdesliEmailWiFi = 2;
                  }
               }
            }else if(PoradiSekvenceOdesliEmailWiFi == 2){
               // ------------------- ODESLÁNÍ ZPRÁVY ---------------------
               if(PocetOpakovaniPrikazuWiFi > 2){
                  message.clear();
                  smtp.sendingResult.clear();
                  OdesliEmail                   = false;
                  OdeselPrikazDoWIFI            = false; // Unlocking WIFI next commands
                  PoradiSekvenceOdesliEmailWiFi = 0;
                  VyresHlaseniWIFIEmailem(4);
               }else{
                  if (!MailClient.sendMail(&smtp, &message, true)){
                     OdeselPrikazDoWIFI = false; // Unlocking WIFI next commands
                     if(smtp.closeSession() == true){
                     }else{
                     }
                     PoradiSekvenceOdesliEmailWiFi = 0;
                     VyresHlaseniWIFIEmailem(4);
                     PocetOpakovaniPrikazuWiFi++;
                  }else{
                     PoradiSekvenceOdesliEmailWiFi = 3;
                     VyresHlaseniWIFIEmailem(2);
                  }
               }
            }else if(PoradiSekvenceOdesliEmailWiFi == 3){
               // ------------------- ČIŠTĚNÍ ---------------------
               smtp.sendingResult.clear();
               message.clear();
               OdesliEmail                   = false; // Sending finished, cycle already will not continue
               OdeselPrikazDoWIFI            = false; // Unlocking WIFI next commands
               PoradiSekvenceOdesliEmailWiFi = 0;
            }

Additional information and things you've tried:
Only notice: Because sending of e-mail takes some time and device is in this time busy and I need to be subroutine for e-mail works simoutaneously with other parts of program, sequence is separated to 4 steps, guided by "PoradiSekvenceOdesliEmailWiFi" variable.
Variables (objects) session and message are defined like a global variables.
I tried find on internet any methode how immediately after start device and connected it to the internet, synchronise time. I'v found nothing. :-( I don'T know what it happens automatically and whether is it necessary.

Recommended memory settings in ESP8266 Arduino Core SDK v3.0.0

Arduino IDE

When you update the ESP8266 Arduino Core SDK to v3.0.0, the memory can be configurable from Arduino IDE board settings.

By default MMU option 1 was selected, the free Heap can be low and may not suitable for the SSL client usage in this library.

To increase the Heap, choose the MMU option 3, 16KB cache + 48KB IRAM and 2nd Heap (shared).

IDE config

More about MMU settings.
https://arduino-esp8266.readthedocs.io/en/latest/mmu.html

PlatformIO IDE

When Core SDK v3.0.0 becomes available in PlatformIO,

By default the balanced ratio (32KB cache + 32KB IRAM) configuration is used.

To increase the heap, PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED build flag should be assigned in platformio.ini.

At the time of writing, to update SDK to v3.0.0 you can follow these steps.

  1. In platformio.ini, edit the config as the following
[env:d1_mini]
platform = https://github.com/platformio/platform-espressif8266.git
build_flags = -D PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
board = d1_mini
framework = arduino
monitor_speed = 115200
  1. Delete this folder C:\Users\UserName\.platformio\platforms\espressif8266@src-?????????????
  2. Delete .pio and .vscode folders in your project.
  3. Clean and Compile the project.

The supportedd MMU build flags in PlatformIO.

  • PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48
    16KB cache + 48KB IRAM (IRAM)

  • PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
    16KB cache + 48KB IRAM and 2nd Heap (shared)

  • PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM32_SECHEAP_NOTSHARED
    16KB cache + 32KB IRAM + 16KB 2nd Heap (not shared)

  • PIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_128K
    128K External 23LC1024

  • PIO_FRAMEWORK_ARDUINO_MMU_EXTERNAL_1024K
    1M External 64 MBit PSRAM

  • PIO_FRAMEWORK_ARDUINO_MMU_CUSTOM
    Disables default configuration and expects user-specified flags

Test code for MMU

#include <Arduino.h>
#include <umm_malloc/umm_heap_select.h>

void setup() 
{
  Serial.begin(74880);
  HeapSelectIram ephemeral;
  Serial.printf("IRAM free: %6d bytes\r\n", ESP.getFreeHeap());
  {
    HeapSelectDram ephemeral;
    Serial.printf("DRAM free: %6d bytes\r\n", ESP.getFreeHeap());
  }
}

void loop() {
  // put your main code here, to run repeatedly:
}

SD_Card_Mounting

Hello Mobizt

I used esp32 and tried to send a file .csv from SD card via Email but I could not send the file.

Please Help.

I do not understand the function name SD_Card_Mounting its did not work.

My code

#include <Arduino.h>

#include <WiFi.h>
#include <SD.h>

#include <ESP_Mail_Client.h>
#include <extras/SDHelper.h>

#define WIFI_SSID "my_wifi"
#define WIFI_PASSWORD "password"

#define SMTP_HOST "smtp.gmail.com"

#define SMTP_PORT 587

#define AUTHOR_EMAIL "[email protected]"
#define AUTHOR_PASSWORD "mypassword"

SMTPSession smtp;

void smtpCallback(SMTP_Status status);

#define sd_cs 12
#define sd_sck 14
#define sd_miso 27
#define sd_mosi 13
#define sd_freq 80000000

#define SPI_SCK_PIN 14
#define SPI_MISO_PIN 27
#define SPI_MOSI_PIN 13
#define SPI_CS_PIN 12
#define ESP32

bool sd_initial_succress = false;
bool flag_sdcard = false;

//SPIClass spiSD( HSPI );

//SPIClass spi;

void setup()
{

Serial.begin(115200);
Serial.print("Connecting Internet");

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(200);
}

Serial.println();
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();

// spiSD.begin( sd_sck, sd_miso, sd_mosi, sd_cs );
// if ( SD.begin( sd_cs, spiSD ) ) flag_sdcard = true;
// flag_sdcard ? Serial.println( "SD initial" ) : Serial.println( "SD fail" );

Serial.println("In");
sd_initial_succress = SD_Card_Mounting();
sd_initial_succress ? Serial.println( "SD initial" ) : Serial.println( "SD fail" );
delay( portMAX_DELAY );

smtp.debug(1);
smtp.callback(smtpCallback);
ESP_Mail_Session session;

session.server.host_name = SMTP_HOST;
session.server.port = SMTP_PORT;
session.login.email = AUTHOR_EMAIL;
session.login.password = AUTHOR_PASSWORD;
session.login.user_domain = F("mydomain.net");

session.time.ntp_server = F("pool.ntp.org,time.nist.gov");
session.time.gmt_offset = 3;
session.time.day_light_offset = 0;

SMTP_Message message;

message.enable.chunking = true;

message.sender.name = F("ESP Mail");
message.sender.email = AUTHOR_EMAIL;

message.subject = F("Test SD card");

message.addRecipient(F("user1"), F("[email protected]"));

String htmlMsg = "<span style="color:#ff0000;">This message contains 1 inline image and 1 attachment file.

<img src="orange.png" width="100" height="100">";
message.html.content = htmlMsg;
message.html.charSet = F("utf-8");

message.html.transfer_encoding = Content_Transfer_Encoding::enc_qp;
message.text.content = F("This message contains 1 inline image and 1 attachment file.\r\nThe inline images were not shown in the plain text message.");
message.text.charSet = F("utf-8");
message.text.transfer_encoding = Content_Transfer_Encoding::enc_base64;
message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal;

SMTP_Attachment att[1];
int attIndex = 0;

att[attIndex].descr.filename = F("dataloger_20220422.csv");
att[attIndex].descr.mime = F("application/octet-stream"); //csv
att[attIndex].file.path = F("/m_202204.csv");
att[attIndex].file.storage_type = esp_mail_file_storage_type_sd;
att[attIndex].descr.transfer_encoding = Content_Transfer_Encoding::enc_base64;

message.addAttachment(att[attIndex]);

if (!smtp.connect(&session))
return;

if (!MailClient.sendMail(&smtp, &message, true))
Serial.println("Error sending Email, " + smtp.errorReason());

ESP_MAIL_PRINTF("Free Heap: %d\n", MailClient.getFreeHeap());
}

void loop()
{
delay(portMAX_DELAY);
}

void smtpCallback(SMTP_Status status)
{
/* Print the current status */
Serial.println(status.info());

/* Print the sending result */
if (status.success())
{
Serial.println("----------------");
ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount());
ESP_MAIL_PRINTF("Message sent failled: %d\n", status.failedCount());
Serial.println("----------------\n");
struct tm dt;

for (size_t i = 0; i < smtp.sendingResult.size(); i++)
{
  /* Get the result item */
  SMTP_Result result = smtp.sendingResult.getItem(i);
  time_t ts = (time_t)result.timestamp;
  localtime_r(&ts, &dt);

  ESP_MAIL_PRINTF("Message No: %d\n", i + 1);
  ESP_MAIL_PRINTF("Status: %s\n", result.completed ? "success" : "failed");
  ESP_MAIL_PRINTF("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec);
  ESP_MAIL_PRINTF("Recipient: %s\n", result.recipients.c_str());
  ESP_MAIL_PRINTF("Subject: %s\n", result.subject.c_str());
}
Serial.println("----------------\n");

//You need to clear sending result as the memory usage will grow up.
smtp.sendingResult.clear();

}
}

Deleting Messages does no longer work

Build tool used:

  • Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • ESP32-based

Other Libraries That are used:

Description of problem:
After updating from library version 1.5.2 to 1.5.5 I noticed, that I can no longer delete messages. In order to ensure the problem was not in my code I reproduced the problem with a slightly adapted version of the Delete_Messages.ino sample sketch (see below).

Share code snippet to reproduce the issue:

/**
 * This example showed how to delete messages from the opened mailbox folder.
 * 
 * Email: [email protected]
 * 
 * Github: https://github.com/mobizt/ESP-Mail-Client
 * 
 * Copyright (c) 2021 mobizt
 *
*/

/** To receive Email using Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en
 * and also https://accounts.google.com/b/0/DisplayUnlockCaptcha
 * 
*/

/** For ESP8266, with BearSSL WiFi Client 
 * The memory reserved for completed valid SSL response from IMAP is 16 kbytes which
 * may cause your device out of memory reset in case the memory 
 * allocation error.
*/

#include <Arduino.h>
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include <ESP_Mail_Client.h>

//To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h.

#define WIFI_SSID "xxxxx"
#define WIFI_PASSWORD "xxxxxxxxx"

/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */
#define IMAP_HOST "xxxx.xxxx.xxxx.xxx"

/** The imap port e.g. 
 * 143  or esp_mail_imap_port_143
 * 993 or esp_mail_imap_port_993
*/
#define IMAP_PORT 993

/* The log in credentials */
#define AUTHOR_EMAIL "[email protected]"
#define AUTHOR_PASSWORD "xxxxxxxxxx"

/* Print the list of mailbox folders */
void printAllMailboxesInfo(IMAPSession &imap);

/* Print the selected folder info */
void printSelectedMailboxInfo(IMAPSession &imap);

/* The IMAP Session object used for Email reading */
IMAPSession imap;

void setup()
{

    Serial.begin(115200);

#if defined(ARDUINO_ARCH_SAMD)
    while (!Serial)
        ;
    Serial.println();
    Serial.println("**** Custom built WiFiNINA firmware need to be installed.****\nTo install firmware, read the instruction here, https://github.com/mobizt/ESP-Mail-Client#install-custom-built-wifinina-firmware");

#endif

    Serial.println();

    Serial.print("Connecting to AP");

    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    while (WiFi.status() != WL_CONNECTED)
    {
        Serial.print(".");
        delay(200);
    }

    Serial.println("");
    Serial.println("WiFi connected.");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    Serial.println();

    /** Enable the debug via Serial port 
     * none debug or 0
     * basic debug or 1
     * 
     * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h
    */
    imap.debug(333);

    /* Declare the session config data */
    ESP_Mail_Session session;

    /* Set the session config */
    session.server.host_name = IMAP_HOST;
    session.server.port = IMAP_PORT;
    session.login.email = AUTHOR_EMAIL;
    session.login.password = AUTHOR_PASSWORD;

    /* Setup the configuration for searching or fetching operation and its result */
    IMAP_Config config;

    /* Connect to server with the session and config */
    if (!imap.connect(&session, &config))
        return;

    /*  {Optional} */
    printAllMailboxesInfo(imap);

    /* Open or select the mailbox folder to read or search the message */
    if (!imap.selectFolder("INBOX",false))
        return;

    /* Define the MessageList class to add the message to delete */
    MessageList toDelete;

   /* Add message uid to delete to the list */

    toDelete.add(136);
    /* Delete all messages permanently by assign the second param to true*/
    imap.deleteMessages(&toDelete, true);


    ESP_MAIL_PRINTF("Free Heap: %d\n", MailClient.getFreeHeap());
}

void loop()
{
}

void printAllMailboxesInfo(IMAPSession &imap)
{
    /* Declare the folder collection class to get the list of mailbox folders */
    FoldersCollection folders;

    /* Get the mailbox folders */
    if (imap.getFolders(folders))
    {
        for (size_t i = 0; i < folders.size(); i++)
        {
            /* Iterate each folder info using the  folder info item data */
            FolderInfo folderInfo = folders.info(i);
            ESP_MAIL_PRINTF("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : "");
        }
    }
}

And here is the serial output:

Connecting to AP...........
WiFi connected.
IP address: 
xxx.xxx.xxx.xxx

> C: ESP Mail Client v1.5.5
> C: connect to IMAP server
> C: host > imap.swizzonic-mail.ch
> C: port > 993
> C: starting socket
> C: connecting to Server
> C: seeding the random number generator
> C: setting up the SSL/TLS structure
! W: Skipping SSL Verification. INSECURE!
> C: setting hostname for TLS session
> C: performing the SSL/TLS handshake
> C: verifying peer X.509 certificate
> C: server connected
> C: check the capability
$ CAPABILITY
* OK swizzonic-mail.ch CommuniGate Pro IMAP Server 7.1.0 ready
* CAPABILITY IMAP4 IMAP4REV1 ACL NAMESPACE UIDPLUS IDLE LITERAL+ QUOTA ID MULTIAPPEND LISTEXT CHILDREN BINARY ESEARCH LOGIN-REFERRALS UNSELECT SASL-IR LIST-EXTENDED SPECIAL-USE CREATE-SPECIAL-USE XLIST AUTH=LOGIN AUTH=PLAIN
$ OK completed
> C: send imap command, LOGIN
$ LOGIN [email protected] xxxxxxxxxxxxx
$ OK completed
> C: send imap command, LIST
$ LIST "" *
* LIST (\HasNoChildren \UnMarked) "/" INBOX
* LIST (\HasNoChildren \UnMarked) "/" Trash
$ OK completed

Available folders: INBOX, Trash
> C: open the mailbox folder
$ SELECT "INBOX"
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Hidden $Media $Forwarded Junk $Label1 $Label2 $Label3)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Hidden $Media $Forwarded Junk $Label1 $Label2 $Label3)] limited
* 4 EXISTS
* 0 RECENT
* OK [UIDNEXT 137] predicted next UID
* OK [UIDVALIDITY 402276210] UIDs valid
* OK [UNSEEN 2] message 2 is first unseen
$ OK [READ-WRITE] SELECT completed
> C: open the mailbox folder
$ SELECT ""
$ NO mailbox does not exist
> E: mailbox does not exist
Free Heap: 174351

Additional information and things you've tried:
Deleting messages still works in version 1.5.3. I assume the problem is related to the introduction of MBSTRING. After some investigation I noticed that _currentFolder seems to be empty when IMAPSession::deleteMessages is called. Deleting messages seems to work, after changing _currentFolder to std::string in ESP_Mail_Client.h (line 2834).

Unable to connect to gmail since they disabled "less secure apps" on May 30, 2022

Build tool used:

  • [X ] Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • [X ] ESP32-based

Other Libraries That are used:

None

Description of problem:
It appears as of May 30, 2022 gmail has turned off "less secure apps" which has broken connecting to the gmail server on port 465. I'm getting this error:
< S: 535-5.7.8 Username and Password not accepted. Learn more at
< S: 535 5.7.8 https://support.google.com/mail/?p=BadCredentials je7-20020a170903264700b001676f87473fsm4313619plb.302 - gsmtp

E: authentication failed
My username and password are correct. I can log in to gmail.com with them using a browser no problem. I'm using code provided by https://microcontrollerslab.com/esp32-send-emails-through-smtp-server-arduino-ide/. How can I get ESP-Mail-Client working now that gmail has disabled "less secure apps"?

Share code snippet to reproduce the issue:

PASTE .cpp / .ino code here

#include <Arduino.h>
#include <WiFi.h>
#include <ESP_Mail_Client.h>

#define WIFI_SSID "Your_SSID"
#define WIFI_PASSWORD "Your_Password"

#define SMTP_server "smtp.gmail.com"
#define SMTP_Port 465


#define sender_email "Write_Sender_Email_address"
#define sender_password "Write_Sender_Email_Password"

#define Recipient_email "Write_recipient_Email_address"


SMTPSession smtp;

void setup(){
  Serial.begin(115200);
  Serial.println();
  Serial.print("Connecting...");
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED){
    Serial.print(".");
    delay(200);
  }
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println();
  smtp.debug(1);


  ESP_Mail_Session session;


  session.server.host_name = SMTP_server ;
  session.server.port = SMTP_Port;
  session.login.email = sender_email;
  session.login.password = sender_password;
  session.login.user_domain = "";

  /* Declare the message class */
  SMTP_Message message;


  message.sender.name = "ESP32";
  message.sender.email = sender_email;
  message.subject = "ESP32 Testing Email";
  message.addRecipient("Microcontrollerslab",Recipient_email);

   //Send HTML message
  String htmlMsg = "<div style=\"color:#FF0000;\"><h1>Hello Microcontrollerslab!</h1><p>This is an HTML email sent from ESP Board</p></div>";
  message.html.content = htmlMsg.c_str();
  message.html.content = htmlMsg.c_str();
  message.text.charSet = "us-ascii";
  message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit; 

 /* 
  //Send simple text message
  String textMsg = "Hello Microcontrollerslab! This is a simple text sent from ESP board";
  message.text.content = textMsg.c_str();
  message.text.charSet = "us-ascii";
  message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit; */


  if (!smtp.connect(&session))
    return;


  if (!MailClient.sendMail(&smtp, &message))
    Serial.println("Error sending Email, " + smtp.errorReason());
 
}

void loop(){

}

Additional information and things you've tried:

How to only receive the unseen msg?

Build tool used:

  • Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • ESP32-based

Other Libraries That are used:

Description of problem:
I test example "Read_Single_Email" (V1.5.2),and set config like this:
config.fetch.set_seen = true;
config.search.criteria = "";
config.search.unseen_msg = true;
and the mail box (outlook.com) has a unseen msg email . When I run first time Read_Single_Email , it can receive the email and be set seen. But when I run second time (reset esp32), that msg(be set seen) was received again.
I want to only receive the unseen msg , I not sure is a bug or setting error... Thanks.

Share code snippet to reproduce the issue:

void setup()
{

    Serial.begin(115200);

#if defined(ARDUINO_ARCH_SAMD)
    while (!Serial)
        ;
    Serial.println();
    Serial.println("**** Custom built WiFiNINA firmware need to be installed.****\nTo install firmware, read the instruction here, https://github.com/mobizt/ESP-Mail-Client#install-custom-built-wifinina-firmware");

#endif

    Serial.println();

    Serial.print("Connecting to AP");

    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    while (WiFi.status() != WL_CONNECTED)
    {
        Serial.print(".");
        delay(200);
    }

    Serial.println("");
    Serial.println("WiFi connected.");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    Serial.println();

    /** Enable the debug via Serial port 
     * none debug or 0
     * basic debug or 1
     * 
     * Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h
    */
    imap.debug(1);

    /* Set the callback function to get the reading results */
    imap.callback(imapCallback);

    /** In case the SD card/adapter was used for the file storagge, the SPI pins can be configure from
     * MailClient.sdBegin function which may be different for ESP32 and ESP8266
     * For ESP32, assign all of SPI pins
     * MailClient.sdBegin(14,2,15,13)
     * Which SCK = 14, MISO = 2, MOSI = 15 and SS = 13
     * And for ESP8266, assign the CS pins of SPI port
     * MailClient.sdBegin(15)
     * Which pin 15 is the CS pin of SD card adapter
    */

    /* Declare the session config data */
    ESP_Mail_Session session;

    /** ########################################################
     * Some properties of IMAP_Config and ESP_Mail_Session data
     * accept the pointer to constant char i.e. const char*. 
     * 
     * You may assign a string literal to that properties like 
     * below example.
     *   
     * config.storage.saved_path = String("/email_data").c_str();
     * 
     * String folder = "INBOX";
     * imap.selectFolder(folder.c_str());
     * 
     * ###########################################################
    */

    /* Set the session config */
    session.server.host_name = IMAP_HOST;
    session.server.port = IMAP_PORT;
    session.login.email = AUTHOR_EMAIL;
    session.login.password = AUTHOR_PASSWORD;


    /* Setup the configuration for searching or fetching operation and its result */
    IMAP_Config config;

    /* Set seen flag */
    config.fetch.set_seen = true;

    /* Search criteria */
    config.search.criteria = "";

    /* Also search the unseen message */
    config.search.unseen_msg = true;

    /* Set the storage to save the downloaded files and attachments */
    config.storage.saved_path = "/email_data";

    /** The file storage type e.g.
     * esp_mail_file_storage_type_none,
     * esp_mail_file_storage_type_flash, and 
     * esp_mail_file_storage_type_sd 
    */
    config.storage.type = esp_mail_file_storage_type_sd;

    /** Set to download heades, text and html messaeges, 
     * attachments and inline images respectively.
    */
    config.download.header = true;
    config.download.text = true;
    config.download.html = true;
    config.download.attachment = true;
    config.download.inlineImg = true;

    /** Set to enable the results i.e. html and text messaeges 
     * which the content stored in the IMAPSession object is limited
     * by the option config.limit.msg_size.
     * The whole message can be download through config.download.text
     * or config.download.html which not depends on these enable options.
    */
    config.enable.html = true;
    config.enable.text = true;

    /* Set to enable the sort the result by message UID in the ascending order */
    config.enable.recent_sort = true;

    /* Set to report the download progress via the default serial port */
    config.enable.download_status = true;

    /* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud
    , to allow case sensitive parse, uncomment below line*/
    //config.enable.header_case_sesitive = true;

    /* Set the limit of number of messages in the search results */
    config.limit.search = 5;

    /** Set the maximum size of message stored in 
     * IMAPSession object in byte
    */
    config.limit.msg_size = 512;

    /** Set the maximum attachments and inline images files size
     * that can be downloaded in byte. 
     * The file which its size is largger than this limit may be saved 
     * as truncated file.
    */
    config.limit.attachment_size = 1024 * 1024 * 5;


    /* Connect to server with the session and config */
    if (!imap.connect(&session, &config))
        return;

    /*  {Optional} */
    printAllMailboxesInfo(imap);

    /* Open or select the mailbox folder to read or search the message */
    if (!imap.selectFolder("INBOX"))
        return;

    /*  {Optional} */
    printSelectedMailboxInfo(imap);

    /** Message UID to fetch or read e.g. 100. 
     * In this case we will get the UID from the max message number (lastest message) 
    */
    String uid = String(imap.getUID(imap.selectedFolder().msgCount()));

    config.fetch.uid = uid.c_str();

    /* Read or search the Email and close the session */
    MailClient.readMail(&imap);

    /* Clear all stored data in IMAPSession object */
    imap.empty();
}

void loop()
{

}

/* Callback function to get the Email reading status */
void imapCallback(IMAP_Status status)
{
    /* Print the current status */
    Serial.println(status.info());

    /* Show the result when reading finished */
    if (status.success())
    {
        /* Print the result */
        printMessages(imap);

        /* Clear all stored data in IMAPSession object */
        imap.empty();
    }
}

void printAllMailboxesInfo(IMAPSession &imap)
{
    /* Declare the folder collection class to get the list of mailbox folders */
    FoldersCollection folders;

    /* Get the mailbox folders */
    if (imap.getFolders(folders))
    {
        for (size_t i = 0; i < folders.size(); i++)
        {
            /* Iterate each folder info using the  folder info item data */
            FolderInfo folderInfo = folders.info(i);
            ESP_MAIL_PRINTF("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : "");
        }
    }
}

void printSelectedMailboxInfo(IMAPSession &imap)
{
    /* Declare the selected folder info class to get the info of selected mailbox folder */
    SelectedFolderInfo sFolder = imap.selectedFolder();

    /* Show the mailbox info */
    ESP_MAIL_PRINTF("\nInfo of the selected folder\nTotal Messages: %d\n", sFolder.msgCount());
    ESP_MAIL_PRINTF("Predicted next UID: %d\n", sFolder.nextUID());
    for (size_t i = 0; i < sFolder.flagCount(); i++)
        ESP_MAIL_PRINTF("%s%s%s", i == 0 ? "Flags: " : ", ", sFolder.flag(i).c_str(), i == sFolder.flagCount() - 1 ? "\n" : "");
}

void printRFC822Messages(IMAP_MSG_Item &msg)
{
    ESP_MAIL_PRINTF("RFC822 Messages: %d message(s)\n****************************\n", msg.rfc822.size());
    for (size_t j = 0; j < msg.rfc822.size(); j++)
    {
        IMAP_MSG_Item rfc822 = msg.rfc822[j];
        ESP_MAIL_PRINTF("%d. \n", j + 1);
        ESP_MAIL_PRINTF("Messsage ID: %s\n", rfc822.messageID);
        ESP_MAIL_PRINTF("From: %s\n", rfc822.from);
        ESP_MAIL_PRINTF("Sender: %s\n", rfc822.sender);
        ESP_MAIL_PRINTF("To: %s\n", rfc822.to);
        ESP_MAIL_PRINTF("CC: %s\n", rfc822.cc);
        ESP_MAIL_PRINTF("Subject: %s\n", rfc822.subject);
        ESP_MAIL_PRINTF("Date: %s\n", rfc822.date);
        ESP_MAIL_PRINTF("Reply-To: %s\n", rfc822.reply_to);
        ESP_MAIL_PRINTF("Return-Path: %s\n", rfc822.return_path);
        ESP_MAIL_PRINTF("Comment: %s\n", rfc822.comment);
        ESP_MAIL_PRINTF("Keyword: %s\n", rfc822.keyword);
        ESP_MAIL_PRINTF("Text Message: %s\n", rfc822.text.content);
        ESP_MAIL_PRINTF("Text Message Charset: %s\n", rfc822.text.charSet);
        ESP_MAIL_PRINTF("Text Message Transfer Encoding: %s\n", rfc822.text.transfer_encoding);
        ESP_MAIL_PRINTF("HTML Message: %s\n", rfc822.html.content);
        ESP_MAIL_PRINTF("HTML Message Charset: %s\n", rfc822.html.charSet);
        ESP_MAIL_PRINTF("HTML Message Transfer Encoding: %s\n\n", rfc822.html.transfer_encoding);

        if (rfc822.attachments.size() > 0)
            printAttacements(rfc822);
    }
}

void printAttacements(IMAP_MSG_Item &msg)
{
    ESP_MAIL_PRINTF("Attachment: %d file(s)\n****************************\n", msg.attachments.size());
    for (size_t j = 0; j < msg.attachments.size(); j++)
    {
        IMAP_Attach_Item att = msg.attachments[j];
        /** att.type can be
         * esp_mail_att_type_none or 0
         * esp_mail_att_type_attachment or 1
         * esp_mail_att_type_inline or 2
        */
        ESP_MAIL_PRINTF("%d. Filename: %s, Name: %s, Size: %d, MIME: %s, Type: %s, Creation Date: %s\n", j + 1, att.filename, att.name, att.size, att.mime, att.type == esp_mail_att_type_attachment ? "attachment" : "inline", att.creationDate);
    }
    Serial.println();
}

void printMessages(IMAPSession &imap)
{
    /* Get the message list from the message list data */
    IMAP_MSG_List msgList = imap.data();

    for (size_t i = 0; i < msgList.msgItems.size(); i++)
    {
        /* Iterate to get each message data through the message item data */
        IMAP_MSG_Item msg = msgList.msgItems[i];

        Serial.println("################################");
        ESP_MAIL_PRINTF("Messsage Number: %s\n", msg.msgNo);
        ESP_MAIL_PRINTF("Messsage UID: %s\n", msg.UID);
        ESP_MAIL_PRINTF("Messsage ID: %s\n", msg.ID);
        ESP_MAIL_PRINTF("Accept Language: %s\n", msg.acceptLang);
        ESP_MAIL_PRINTF("Content Language: %s\n", msg.contentLang);
        ESP_MAIL_PRINTF("From: %s\n", msg.from);
        ESP_MAIL_PRINTF("From Charset: %s\n", msg.fromCharset);
        ESP_MAIL_PRINTF("To: %s\n", msg.to);
        ESP_MAIL_PRINTF("To Charset: %s\n", msg.toCharset);
        ESP_MAIL_PRINTF("CC: %s\n", msg.cc);
        ESP_MAIL_PRINTF("CC Charset: %s\n", msg.ccCharset);
        ESP_MAIL_PRINTF("Date: %s\n", msg.date);
        ESP_MAIL_PRINTF("Subject: %s\n", msg.subject);
        ESP_MAIL_PRINTF("Subject Charset: %s\n", msg.subjectCharset);

        /* If the result contains the message info (Fetch mode) */
        if (!imap.headerOnly())
        {
            ESP_MAIL_PRINTF("Text Message: %s\n", msg.text.content);
            ESP_MAIL_PRINTF("Text Message Charset: %s\n", msg.text.charSet);
            ESP_MAIL_PRINTF("Text Message Transfer Encoding: %s\n", msg.text.transfer_encoding);
            ESP_MAIL_PRINTF("HTML Message: %s\n", msg.html.content);
            ESP_MAIL_PRINTF("HTML Message Charset: %s\n", msg.html.charSet);
            ESP_MAIL_PRINTF("HTML Message Transfer Encoding: %s\n\n", msg.html.transfer_encoding);

            if (msg.attachments.size() > 0)
                printAttacements(msg);

            if (msg.rfc822.size() > 0)
                printRFC822Messages(msg);
        }

        Serial.println();
    }
}

Additional information and things you've tried:
===============First time run==============
ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4

Connecting to AP........................................................................................ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4

Connecting to AP...........
WiFi connected.
IP address:
192.168.8.160

Connecting to IMAP server...

C: ESP Mail Client v1.5.2
C: connect to IMAP server
C: host > outlook.office365.com
C: port > 993
C: starting socket
C: connecting to Server
C: seeding the random number generator
C: setting up the SSL/TLS structure
! W: Skipping SSL Verification. INSECURE!
C: setting hostname for TLS session
C: performing the SSL/TLS handshake
C: verifying peer X.509 certificate
IMAP server connected
C: server connected

Check the capability...

C: check the capability

Logging in...

C: send imap command, LOGIN

Reading the list of mailboxes...

C: send imap command, LIST

Available folders: Notes, Drafts, &W1hoYw-, Outbox, Junk, Inbox, Sent, Deleted

Selecting the INBOX folder...

C: open the mailbox folder

Info of the selected folder
Total Messages: 3
Predicted next UID: 51
Flags: \Seen, \Answered, \Flagged, \Deleted, \Draft, $MDNSent
Get UID...

C: Get UID...
UID is 47
C: UID is 47

Selecting the INBOX folder...

C: open the mailbox folder

Fetching message 1, UID: 47

C: send imap command, FETCH
C: fetch message header
C: fetch body part header, 1
C: fetch body sub part header, 1.1
C: fetch body sub part header, 1.2
C: fetch body sub part header, 1.3
C: fetch body part header, 2
C: fetch body sub part header, 2.1
C: fetch body sub part header, 2.2
C: fetch body sub part header, 2.3
C: fetch body part header, 3

Downloading messages...

C: download plain TEXT message
download /email_data/47/msg.txt, 100%
C: download HTML message
download /email_data/47/msg.html, 100%

Downloading attachments...

C: download attachment
download haun.png, 0%
download haun.png, 60%
download haun.png, 100%
C: download attachment
download mu_law.wav, 0%
download mu_law.wav, 20%
download mu_law.wav, 40%
download mu_law.wav, 60%
download mu_law.wav, 100%

Saving message header to file...

C: Free Heap: 225176

Logging out...

C: send imap command, LOGOUT

Message fetch cmpleted

C: message fetch completed
C: cleaning SSL connection

################################
Messsage Number: 1
Messsage UID: 47
Messsage ID: SG2PR02MB444338D44C48090AC491438CC9DB9@SG2PR02MB4443.apcprd02.prod.outlook.com
Accept Language:
Content Language:
From: ESP Mail[email protected]
From Charset:
To: user1[email protected]
To Charset:
CC:
CC Charset:
Date: Wed, 15 Sep 2021 01:37:15 +0000
Subject: Test sending Email with parallel attachments
Subject Charset:
Text Message: This message contains image and audio file which will play on the Mail client in parallel or simultaneously (depends on the client supports).
Text Message Charset: us-ascii
Text Message Transfer Encoding: base64
HTML Message: <s=pan style="color:#ff0000;">This message contains image and audio file whi=ch will play on the Mail client in parallel or simultaneously (depends on t=he client supports).
HTML Message Charset: utf-8
HTML Message Transfer Encoding: quoted-printable

Attachment: 2 file(s)


  1. Filename: haun.png, Name: haun.png, Size: 7235, MIME: image/png, Type: attachment, Creation Date:
  2. Filename: mu_law.wav, Name: mu_law.wav, Size: 23966, MIME: audio/basic, Type: attachment, Creation Date:

============Second time run (reset) ============
ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4

Connecting to AP.....................
WiFi connected.
IP address:
192.168.8.160

Connecting to IMAP server...

C: ESP Mail Client v1.5.2
C: connect to IMAP server
C: host > outlook.office365.com
C: port > 993
C: starting socket
C: connecting to Server
C: seeding the random number generator
C: setting up the SSL/TLS structure
! W: Skipping SSL Verification. INSECURE!
C: setting hostname for TLS session
C: performing the SSL/TLS handshake
C: verifying peer X.509 certificate
IMAP server connected
C: server connected

Check the capability...

C: check the capability

Logging in...

C: send imap command, LOGIN

Reading the list of mailboxes...

C: send imap command, LIST

Available folders: Notes, Drafts, &W1hoYw-, Outbox, Junk, Inbox, Sent, Deleted

Selecting the INBOX folder...

C: open the mailbox folder

Info of the selected folder
Total Messages: 3
Predicted next UID: 51
Flags: \Seen, \Answered, \Flagged, \Deleted, \Draft, $MDNSent
Get UID...

C: Get UID...
UID is 47
C: UID is 47

Selecting the INBOX folder...

C: open the mailbox folder

Fetching message 1, UID: 47

C: send imap command, FETCH
C: fetch message header
C: fetch body part header, 1
C: fetch body sub part header, 1.1
C: fetch body sub part header, 1.2
C: fetch body sub part header, 1.3
C: fetch body part header, 2
C: fetch body sub part header, 2.1
C: fetch body sub part header, 2.2
C: fetch body sub part header, 2.3
C: fetch body part header, 3

Downloading messages...

C: download plain TEXT message
download /email_data/47/msg.txt, 100%
C: download HTML message
download /email_data/47/msg.html, 100%

Downloading attachments...

C: download attachment
download haun.png, 0%
download haun.png, 60%
download haun.png, 100%
C: download attachment
download mu_law.wav, 0%
download mu_law.wav, 20%
download mu_law.wav, 40%
download mu_law.wav, 60%
download mu_law.wav, 100%

Saving message header to file...

C: Free Heap: 225012

Logging out...

C: send imap command, LOGOUT

Message fetch cmpleted

C: message fetch completed
C: cleaning SSL connection

################################
Messsage Number: 1
Messsage UID: 47
Messsage ID: SG2PR02MB444338D44C48090AC491438CC9DB9@SG2PR02MB4443.apcprd02.prod.outlook.com
Accept Language:
Content Language:
From: ESP Mail[email protected]
From Charset:
To: user1[email protected]
To Charset:
CC:
CC Charset:
Date: Wed, 15 Sep 2021 01:37:15 +0000
Subject: Test sending Email with parallel attachments
Subject Charset:
Text Message: This message contains image and audio file which will play on the Mail client in parallel or simultaneously (depends on the client supports).
Text Message Charset: us-ascii
Text Message Transfer Encoding: base64
HTML Message: <s=pan style="color:#ff0000;">This message contains image and audio file whi=ch will play on the Mail client in parallel or simultaneously (depends on t=he client supports).
HTML Message Charset: utf-8
HTML Message Transfer Encoding: quoted-printable

Attachment: 2 file(s)


  1. Filename: haun.png, Name: haun.png, Size: 7235, MIME: image/png, Type: attachment, Creation Date:
  2. Filename: mu_law.wav, Name: mu_law.wav, Size: 23966, MIME: audio/basic, Type: attachment, Creation Date:

Search in inbox from multiple email addresses

Hi,
I'm trying to using OR condition search criteria mixed to FROM address.

  1. In first test i setted in config.search.criteria = "UID SEARCH FROM ([email protected] OR [email protected])";
  2. In second test i setted in config.search.criteria = "FROM ([email protected] OR [email protected])";

I already tried with some other criteria mixing "FROM" and "OR" condition, but with no luck.
How is it possible search in inbox mails using multiple email addresses?
Thanks

Call-back function returning garbage in result.recipients and result.subject

Build tool used:

  • [ X] Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • [X ] ESP32-based

Other Libraries That are used:

Description of problem:
When using the library for sending an email. The call back function returns garbage for result.recipients and result.subject. Need to know if this is normal. I really love the new version of your library. First version was great; this one is better.

Share code snippet to reproduce the issue:
/* This function sends an email message. textMsg is the body

  • of the message. The parameters for the email are discussed
  • in the header notes for the program.
    /
    bool EmailMsg(String textMsg) {
    //Set success flag true
    bool MsgSuccess = true;
    //Clear all recipients
    message.clearRecipients();
    message.clearCc();
    message.clearBcc();
    //Send raw text message
    message.addRecipient("PCARS", Recipent_emailStr);
    message.text.content = textMsg.c_str();
    message.text.charSet = "us-ascii";
    message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
    message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low;
    message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay;
    // Set the custom message header
    //message.addHeader("Message-ID: [email protected]");
    //
    ***************************
    // Feed the button process switch status-Make sure that
    // sending email will not allow a door switch to be missed
    SwDoor.read();
    //****************************
    // Connect to server with the session config
    if (!smtp.connect(&session)){
    Serial.println("Connection Failure, " + smtp.errorReason());
    MsgSuccess = false;
    return MsgSuccess;}
    // Start sending Email and close the session
    if (!MailClient.sendMail(&smtp, &message)){
    Serial.println("Error sending Email, " + smtp.errorReason());
    MsgSuccess=false;}
    return MsgSuccess;
    }

/* This funtions handles errors and messages that are

  • created when an email is sent.
    */
    void smtpCallback(SMTP_Status status){
    // Print the current status
    Serial.println(status.info());

// Print the sending result
if (status.success()){
Serial.println("----------------");
ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount());
ESP_MAIL_PRINTF("Message sent failled: %d\n", status.failedCount());
Serial.println("----------------\n");
struct tm dt;

for (size_t i = 0; i < smtp.sendingResult.size(); i++){
  // Get the result item 
  SMTP_Result result = smtp.sendingResult.getItem(i);
  time_t ts = (time_t)result.timestamp;
  localtime_r(&ts, &dt);

  ESP_MAIL_PRINTF("Message No: %d\n", i + 1);
  ESP_MAIL_PRINTF("Status: %s\n", result.completed ? "success" : "failed");
  ESP_MAIL_PRINTF("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec);
  ESP_MAIL_PRINTF("Recipient: %s\n", result.recipients);
  ESP_MAIL_PRINTF("Subject: %s\n", result.subject);
}
Serial.println("----------------\n");

}
}


**Additional information and things you've tried:**

Output from serial monitor.

SMTP server connected, wait for greeting...

Sending greeting response...

Logging in...

Sending next Email...

Sending message header...

Sending message body...

Finishing the message sending...

Closing the session...

Message sent successfully

----------------
Message sent success: 2
Message sent failled: 0
----------------

Message No: 1
Status: success
Date/Time: 1970/1/1 0:1:39
Recipient: ⸮!⸮?�
Subject: �⸮⸮? 
Message No: 2
Status: success
Date/Time: 1970/1/1 0:6:19
Recipient: 4⸮⸮?�
Subject: t!⸮? 
----------------


<!-- LEAVE THIS LINE AS-IS AND DON'T DELETE IT, OTHERWISE THE ISSUE WILL BE CLOSED AUTOMATICALLY. -->

ESP_Mail_Client causing exception error

Hi Mobitz,

let me say "Thank You" for your great work on your mail script.

However, it sometimes runs into an exception error whilst performing the SSL/TLS handshake. Please see print-out below...

It appears to happen occasionally when sending the first mail (after a few hours). After the crash I can trigger the script many times without having any issues.

I tried to run it through the exception decoder, but the information given are meaningless to me.

FYI, I'm using a Wemos D1 R1 board with the latest ESP8266 version (2.7.4). I'm having these problems with either your version 1.0.13. or 1.3.0.. I also changed the email provider from GMail to GMX, but it didn't improve anything

Have you encountered similar problems in the past? Or can you point me in the right direction to look for?

Many Thanks,

AXON24

09:07:47.115 -> Connecting to SMTP server...
09:07:47.115 -> > C: ESP Mail Client v1.3.0
09:07:47.115 -> > C: connect to SMTP server
09:07:47.115 -> > C: host > mail.gmx.net
09:07:47.115 -> > C: port > 587
09:07:47.253 -> > C: smtp server connected
09:07:47.253 ->
09:07:47.253 -> SMTP server connected, wait for greeting...
09:07:47.287 -> < S: 220 gmx.net (mrgmx104) Nemesis ESMTP Service ready
09:07:47.287 ->
09:07:47.287 -> Sending greeting response...
09:07:47.287 -> > C: send smtp command, HELO
09:07:47.370 -> < S: 250-gmx.net Hello mydomain.net [80.228.80.66]
09:07:47.370 -> < S: 250-8BITMIME
09:07:47.370 -> < S: 250-SIZE 69920427
09:07:47.370 -> < S: 250 STARTTLS
09:07:47.370 ->
09:07:47.370 -> Send command, STARTTLS
09:07:47.370 -> > C: send STARTTLS command
09:07:47.370 -> < S: 220 OK
09:07:47.370 -> > C: performing the SSL/TLS handshake
09:07:47.628 ->
09:07:47.628 -> User exception (panic/abort/assert)
09:07:47.628 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
09:07:47.628 ->
09:07:47.628 -> Abort called

Error Compiling Wemos D1 mini pro new Version of library 1.4.0

Hi !

I get this error with the new update

C:\Users\eugen\Documents\Arduino\libraries\ESP_Mail_Client\src/wcs/esp8266/ESP8266_WCS.h:49:1: error: expected class-name before '{' token
 {
 ^
C:\Users\eugen\Documents\Arduino\libraries\ESP_Mail_Client\src/wcs/esp8266/ESP8266_WCS.h:52:3: error: 'ESP8266_WCS::~ESP8266_WCS()' marked override, but does not override
   ~ESP8266_WCS() override;
   ^
C:\Users\eugen\Documents\Arduino\libraries\ESP_Mail_Client\src/wcs/esp8266/ESP8266_WCS.h:54:7: error: 'int ESP8266_WCS::connect(const char*, uint16_t)' marked override, but does not override
   int connect(const char *name, uint16_t port) override;
       ^
C:\Users\eugen\Documents\Arduino\libraries\ESP_Mail_Client\src/wcs/esp8266/ESP8266_WCS.h:55:11: error: 'uint8_t ESP8266_WCS::connected()' marked override, but does not override
   uint8_t connected() override;
           ^
C:\Users\eugen\Documents\Arduino\libraries\ESP_Mail_Client\src/wcs/esp8266/ESP8266_WCS.h:56:7: error: 'int ESP8266_WCS::available()' marked override, but does not override
   int available() override;
       ^
C:\Users\eugen\Documents\Arduino\libraries\ESP_Mail_Client\src/wcs/esp8266/ESP8266_WCS.h:57:7: error: 'int ESP8266_WCS::read()' marked override, but does not override
   int read() override;
       ^
C:\Users\eugen\Documents\Arduino\libraries\ESP_Mail_Client\src/wcs/esp8266/ESP8266_WCS.h:58:7: error: 'int ESP8266_WCS::read(uint8_t*, size_t)' marked override, but does not override
   int read(uint8_t *buf, size_t size) override;
       ^
C:\Users\eugen\Documents\Arduino\libraries\ESP_Mail_Client\src/wcs/esp8266/ESP8266_WCS.h:59:10: error: 'size_t ESP8266_WCS::write(const uint8_t*, size_t)' marked override, but does not override
   size_t write(const uint8_t *buf, size_t size) override;
          ^
C:\Users\eugen\Documents\Arduino\libraries\ESP_Mail_Client\src/wcs/esp8266/ESP8266_WCS.h:60:10: error: 'size_t ESP8266_WCS::write_P(const char*, size_t)' marked override, but does not override
   size_t write_P(PGM_P buf, size_t size) override;
          ^
C:\Users\eugen\Documents\Arduino\libraries\ESP_Mail_Client\src/wcs/esp8266/ESP8266_WCS.h:61:7: error: 'int ESP8266_WCS::peek()' marked override, but does not override
   int peek()override;
       ^
C:\Users\eugen\Documents\Arduino\libraries\ESP_Mail_Client\src/wcs/esp8266/ESP8266_WCS.h:62:10: error: 'size_t ESP8266_WCS::peekBytes(uint8_t*, size_t)' marked override, but does not override
   size_t peekBytes(uint8_t *buffer, size_t length) override;
          ^

Tested with example code 'Send HTML'
ESP8266 2.7.4
Arduino IDE 1.8.13

Google blocks ESP even if less secure app is turned OFF

Hi!

As per title, I was just wondering why the ESP8266 has been blocked from sign in when trying to log in to the SMPT account. It works fine when I use it in my own network, but if it is a different network from another country in the world, google block the access of the ESP even less secure app is turned off.

I know it doesn't seem secure, but that account is just used as a SMPT account.

Any suggestions?

Not compiling

Trying a basic send email. Getting this on compile

In file included from C:\Users\administrator\Documents\Arduino\libraries\SmtpClient/SmtpClient.h:2:0,
from C:\Users\administrator\Documents\projects\data.intelligence.onl\MicroControllers\TempMonitorMK1\TempMonitorMK1.ino:20:
C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/coap/Debug.h:64:28: error: 'LOG_INFO' is not a type
#define info(...) coap_log(LOG_INFO, VA_ARGS)
^
C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/coap/Debug.h:58:37: note: in definition of macro 'coap_log'
#define coap_log(...) coap_log_impl(VA_ARGS)
^
C:\Users\administrator\Documents\Arduino\libraries\ESP-Mail-Client\src/ESP_Mail_Client.h:1787:38: note: in expansion of macro 'info'
struct esp_mail_folder_info_item_t info(size_t index)
^
C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/coap/Debug.h:58:23: error: expected ';' at end of member declaration
#define coap_log(...) coap_log_impl(VA_ARGS)
^
C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/coap/Debug.h:64:19: note: in expansion of macro 'coap_log'
#define info(...) coap_log(LOG_INFO, VA_ARGS)
^
C:\Users\administrator\Documents\Arduino\libraries\ESP-Mail-Client\src/ESP_Mail_Client.h:1824:15: note: in expansion of macro 'info'
const char *info();
^
C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/coap/Debug.h:64:36: error: expected ')' before ',' token
#define info(...) coap_log(LOG_INFO, VA_ARGS)
^
C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/coap/Debug.h:58:37: note: in definition of macro 'coap_log'
#define coap_log(...) coap_log_impl(VA_ARGS)
^
C:\Users\administrator\Documents\Arduino\libraries\ESP-Mail-Client\src/ESP_Mail_Client.h:1824:15: note: in expansion of macro 'info'
const char *info();
^
C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/coap/Debug.h:58:23: error: expected ';' at end of member declaration
#define coap_log(...) coap_log_impl(VA_ARGS)
^
C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/coap/Debug.h:64:19: note: in expansion of macro 'coap_log'
#define info(...) coap_log(LOG_INFO, VA_ARGS)
^
C:\Users\administrator\Documents\Arduino\libraries\ESP-Mail-Client\src/ESP_Mail_Client.h:2125:15: note: in expansion of macro 'info'
const char *info();
^
C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/coap/Debug.h:64:36: error: expected ')' before ',' token
#define info(...) coap_log(LOG_INFO, VA_ARGS)
^
C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/coap/Debug.h:58:37: note: in definition of macro 'coap_log'
#define coap_log(...) coap_log_impl(VA_ARGS)
^
C:\Users\administrator\Documents\Arduino\libraries\ESP-Mail-Client\src/ESP_Mail_Client.h:2125:15: note: in expansion of macro 'info'
const char *info();
^
C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/coap/Debug.h:66:29: error: 'LOG_DEBUG' is not a type
#define debug(...) coap_log(LOG_DEBUG, VA_ARGS)
^
C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/coap/Debug.h:58:37: note: in definition of macro 'coap_log'
#define coap_log(...) coap_log_impl(VA_ARGS)
^
C:\Users\administrator\Documents\Arduino\libraries\ESP-Mail-Client\src/ESP_Mail_Client.h:2418:8: note: in expansion of macro 'debug'
void debug(int level);
^
C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/coap/Debug.h:66:29: error: 'LOG_DEBUG' is not a type
#define debug(...) coap_log(LOG_DEBUG, VA_ARGS)
^
C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/coap/Debug.h:58:37: note: in definition of macro 'coap_log'
#define coap_log(...) coap_log_impl(VA_ARGS)
^
C:\Users\administrator\Documents\Arduino\libraries\ESP-Mail-Client\src/ESP_Mail_Client.h:2650:8: note: in expansion of macro 'debug'
void debug(int level);
^
Multiple libraries were found for "SD.h"
Used: C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\SD
Not used: C:\Program Files (x86)\Arduino\libraries\SD
Multiple libraries were found for "WiFi.h"
Used: C:\Users\administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
exit status 1
Error compiling for board Node32s.

Can't add String to text message

Hi!

I was just using your library and I found it very useful! I was just wondering if was possibile to also send some String in the text message in the email.

For example:

message.html.content = "<br>Temperature is " + String(temp, 1) + "°C<br>Humidity is " + String(humidity) + "%<br>Pressure is " + String(pressurehpa, 1) + "hPa<br>Wind Speed is " + String(WindSpeed, 1) + "km/h from " + DIRECTIONWIND + "<br>Rain Today " + String(mmPioggia, 1) + "mm<br>Rain Intensity is " + String(rainrate, 1) + "mm/h<br>Current UV is " + String(UVindex) + "<br><br><b>Daily Weather Observations</b><br><br>Highest " + String(maxTemp, 1) + "°C<br>Lowest " + String(minTemp, 1) + "°C<br>Gust " + String(Gust, 1) + "km/h<br>Maximum Intensity of Rain " + String(rainrateMax, 1) + "mm/h<br><br><i>To stop this notification go to Services/EmailAlert/EmailNotification and type 'OFF'</i>";

At the moment it gives an error if I try to do that. The Strings are variable.

And also, is it possible to have the possibility to be a variable also the String of the email of the recipient?

For example.

String email = "[email protected]";

 message.addRecipient("Admin", email);

Much appreciate for some feedback!

Thank you!

Error compiling Send_Camera_Image

Build tool used:

Windows 10

  • [X ] Arduino 1.8.13
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • [ X] ESP32-based ESP_CAM

Other Libraries That are used:

Description of problem:
Trying to compile the example, only added the needed parameters as WiFi credentials (lines 34, 35), SMTP server (line 43), AUTHOR_EMAIL and AUTHOR_PASSWORD (lines 53, 54) and message.addRecipient (line 124).

The cam/OV2640.h is present and correctly referenced.

There is something I'm doing wrong but I can't find it.

Rom

sketch\Send_Camera_Image.ino.cpp.o:(.literal._Z7initCamv+0x8): undefined reference to OV2640::init(camera_config_t)'
sketch\Send_Camera_Image.ino.cpp.o:(.literal._Z7initCamv+0xc): undefined reference to OV2640::run()' sketch\Send_Camera_Image.ino.cpp.o:(.literal._Z5setupv+0x8c): undefined reference to OV2640::getfb()'
sketch\Send_Camera_Image.ino.cpp.o:(.literal._Z5setupv+0x90): undefined reference to OV2640::getSize()' sketch\Send_Camera_Image.ino.cpp.o: In function initCam()':
C:\Users\rsan\Documents\Arduino\libraries\ESP_Mail_Client\src/ESP_Mail_Client.h:2713: undefined reference to OV2640::init(camera_config_t)' C:\Users\rsan\Documents\Arduino\libraries\ESP_Mail_Client\src/ESP_Mail_Client.h:2713: undefined reference to OV2640::run()'
sketch\Send_Camera_Image.ino.cpp.o: In function setup()': C:\Users\rsan\Documents\Arduino\libraries\ESP_Mail_Client\src/ESP_Mail_Client.h:2713: undefined reference to OV2640::getfb()'
C:\Users\rsan\Documents\Arduino\libraries\ESP_Mail_Client\src/ESP_Mail_Client.h:2713: undefined reference to OV2640::getSize()' collect2.exe: error: ld returned 1 exit status Multiple libraries were found for "SD.h" Used: C:\Users\rsan\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\SD Not used: C:\Program Files (x86)\Arduino\libraries\SD Not used: C:\Users\rsan\Documents\Arduino\libraries\SD Multiple libraries were found for "WiFi.h" Used: C:\Users\rsan\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi Not used: C:\Program Files (x86)\Arduino\libraries\WiFi exit status 1 Error compiling for board AI Thinker ESP32-CAM.

Share code snippet to reproduce the issue:

PASTE .cpp / .ino code here

Additional information and things you've tried:

I had to remove all the F() macros to get it to work.

Build tool used:

  • [x ] Arudino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Board used (ESP32/ESP8266/Arudino):

  • [x ] ESP8266-based
  • ESP32-based

Other Libraries That are used:

In "Send_Text.ino" example I had to remove all the F() macros to get it to work. Once I did that is sent the email just fine.
Those are the only changes I made to the example code other network and email requirements.
I am not sure it is a bug because I could have something in the IDE set wrong but for not it works.

Description of problem:

Share code snippet to reproduce the issue:

PASTE .cpp / .ino code here

//  session.time.ntp_server = F("pool.ntp.org,time.nist.gov");
  session.time.ntp_server = "pool.ntp.org,time.nist.gov";

Additional information and things you've tried:

Problem with SPIFFS

Hello,
if I try to compile this:
#include <WebServer.h>
#include <ArduinoOTA.h>
#include <SPIFFS.h>
#include <ESP_Mail_Client.h>
//#include <ESP32_MailClient.h>
#include <detail/RequestHandlersImpl.h>
void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}
I get much alarms.


If I try this:
#include <WebServer.h>
#include <ArduinoOTA.h>
#include <SPIFFS.h>
//#include <ESP_Mail_Client.h>
#include <ESP32_MailClient.h>
#include <detail/RequestHandlersImpl.h>
void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}
this will compile.
What I do wrong?
I use a DOIT ESP32 DEVKIT V1

error: control reaches end of non-void function in ESP32_TCP_Client::send()

Build tool used:

  • Arduino
  • Platformio (Visual Studio Code plugin)
  • Platformio CLI
  • Other

Windows 10, Arduino 1.8.13, esp32 1.0.6

Board used (ESP32/ESP8266/Arudino):

  • ESP8266-based
  • ESP32-based

Other Libraries That are used:

none

Description of problem:
In versions 1.3.0 and 1.3.1 of this library, I'm getting the following error when I try to compile programs which include this library.

\Documents\Arduino\libraries\ESP_Mail_Client\src\wcs\esp32\ESP32_TCP_Client.cpp: In member function 'int ESP32_TCP_Client::send(const char*)':
\Documents\Arduino\libraries\ESP_Mail_Client\src\wcs\esp32\ESP32_TCP_Client.cpp:80:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
cc1plus.exe: some warnings being treated as errors

exit status 1
Error compiling for board ESP32 Dev Module.

Share code snippet to reproduce the issue:

The Send_Text example program reproduces the issue.

Additional information and things you've tried:

My interpretation of the issue is that the send method is supposed to return an int, but in some cases there is no return value specified.

I don't know if this is a proper fix for the issue, but adding return 0; to the end of the method did make the error go away and my code start working again.

I would be happy to try to provide more information.

Thank you, Mobizt, for making so many great libraries!

-Joshua

pass SMTPSession to callback

Hi K.,

I enjoy your ESP_Mail_Client.h.

I wrote a function to handle all my mail-send-needs and though I could have all needed vars local. Sadly that does not work if the callback is used like in "send-text" example.

  smtp.callback(smtpCallback);

As far as I see, why not add the reference to SMTPSession into the class SMTP_Status? Or change the callback-call to pass it (that would break compatibility, but lib is quite new...)?

Anyway, I would really prefer to avoid to create a global var (even if it might be only a pointer).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.