mobizt / ESP-Mail-Client

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.
https://mobizt.github.io/ESP-Mail-Client/
MIT License
194 stars 56 forks source link

random but repeatedly problems/errors with smtp blocking eMail functionality #249

Closed ChristofSchmid closed 1 year ago

ChristofSchmid commented 1 year ago

Build tool used:

Board used (ESP32/ESP8266/Arudino):

Other Libraries That are used:

#include <esp_task_wdt.h>  
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
#include <ESP_Mail_Client.h>
#include <CircularBuffer.h>

#include <time.h>
#include <RadioLib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

//Add filesystem
#include "FS.h"
#include <LITTLEFS.h>

Description of problem: First of all, congrats and sthanks to this comprehensive lib. I am very sorry to bug you here, but I cannot solve the problems encouterd myself. Maybe you coild guide me in the right direction.

I have developed an irrigation system and use ESP-Mail-Client to send critical information from the soil sensors attached. I started with v2.7 and moved on to the actual build.

  1. Issue when I close the smtp session after MailClient.sendMail using the param 3 flag true, one mail can be sent. Then I receive an error message "> C: cleaning SSL connection". The next use of .sendMail is successful and so on.
  2. Issue (version of logs and code below) keeping the smtp open works well for a limited time. Then I usually receive an error "! E: SSL - Memory allocation failed" In the logs you can see that after 2+ hours, the .sendMail does nothing anymore

Share code snippet to reproduce the issue:

PASTE .cpp / .ino code here

* Sketch initial code **

/ Rui Santos Complete project details at https://RandomNerdTutorials.com/esp32-websocket-server-arduino/ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. /

// Import required libraries
#include <esp_task_wdt.h>  
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
#include <ESP_Mail_Client.h>
#include <CircularBuffer.h>

#include <time.h>
#include <RadioLib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

//Add filesystem
#include "FS.h"
#include <LITTLEFS.h>
  // Dateisystem automatisch formatieren (true/false)
#define FORMAT_LITTLEFS_IF_FAILED true
#include "defines.h"

//#include "HtmlMainPage.h"
#include "HTML-Herrliberg.h"
#include "HTML-Belo.h"

//add some extra time to send larger eMail.
#define WDT_TIMEOUT 10    

// Storage struct
CircularBuffer<String, CHART_SIZE> chartS1;
CircularBuffer<String, CHART_SIZE> chartS2;
CircularBuffer<String, CHART_SIZE> chartS3;
CircularBuffer<String, CHART_SIZE> chartS4;
CircularBuffer<String, CHART_SIZE> chartS5;
CircularBuffer<String, CHART_SIZE> chartS6;
CircularBuffer<String, CHART_SIZE> chartS7;
CircularBuffer<String, CHART_SIZE> chartS8;

// Create AsyncWebServer object on port 80
AsyncWebServer asWebServer(80);
AsyncWebSocket ws("/ws");

//Setup Display
Adafruit_SSD1306 display(MP_ESP32_SSD1306_WIDTH, MP_ESP32_SSD1306_HEIGHT, &Wire, MP_ESP32_SSD1306_RST);
//Setup LoRa
SX1278 radio = new Module(LORA_CS, DIO0, LORA_RST, DIO1, SPI, SPISettings());  //433Mhz

/* The SMTP Session object used for Email sending */
SMTPSession smtp;

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

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

/* Declare the message class */
SMTP_Message mailMessage;

/* The attachment data item */
SMTP_Attachment MailAtt;

// For Free Heap checking
#include "HeapStat.h"
HeapStat heapInfo;

void setup(){
  //Set watchdog to WDT_TIMEOUT
  esp_task_wdt_init(WDT_TIMEOUT, true); 
  // Serial port for debugging purposes
  Serial.begin(115200);

  //Start Display
  SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
     Wire.begin(MP_ESP32_I2C_SDA, MP_ESP32_I2C_SCL);
    // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
    if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
    { // Address 0x3C for 128x32
        Serial.println(F("SSD1306 allocation failed"));
        for (;;)
            ; // Don't proceed, loop forever
    }

    display.clearDisplay();
    display.setTextSize(1);              // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE); // Draw white text
    display.setCursor(0, 0);             // Start at top-left corner
    display.println(F("Sketch started"));
    display.display();
    delay(1000);

  // Connect to Wi-Fi network with SSID and password
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  // delete old config
  WiFi.disconnect(true);
  delay(1000);
  WiFi.onEvent(WiFiStationConnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_CONNECTED);
  WiFi.onEvent(WiFiGotIP, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP);
  WiFi.onEvent(WiFiStationDisconnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
  delay(50);
  WiFi.begin(ssid, password);

  //start Websocket
  initWebSocket();

  configureWebServer();

  // Start asWebServer
  AsyncElegantOTA.begin(&asWebServer);    // Start ElegantOTA
  asWebServer.begin();

    // initialize SX1278 with default settings
  Serial.print(F("Initializing LoRa... "));

  //int state = radio.begin();
  int state = radio.begin(FREQUENCY, BANDWIDTH, SPREADING_FACTOR, CODING_RATE, SX1278_SYNC_WORD, OUTPUT_POWER, PREAMBLE_LEN, GAIN);
  if (state == RADIOLIB_ERR_NONE) {
    Serial.println(F("success!"));

    Serial.print(F("RSSI:\t\t\t"));
    Serial.print(radio.getRSSI());
    Serial.println(F(" dBm"));

    // print SNR (Signal-to-Noise Ratio)
    // of the last received packet
    Serial.print(F("SNR:\t\t\t"));
    Serial.print(radio.getSNR());
    Serial.println(F(" dB"));

    // print frequency error
    // of the last received packet
    Serial.print(F("Frequency error:\t"));
    Serial.print(radio.getFrequencyError());
    Serial.println(F(" Hz"));

  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
    LoRaMessageToScreen(0);
    while (true);
  }

//eMail SMTP Setup
  /** Enable the debug via Serial port
   * none debug or 0
   * basic debug or 1
  */
  smtp.debug(1);

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

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

  /* Set the session config */
  mailSession.server.host_name = SMTP_HOST;
  mailSession.server.port = SMTP_PORT;
  mailSession.login.email = AUTHOR_EMAIL;
  mailSession.login.password = AUTHOR_PASSWORD;
  mailSession.login.user_domain = "";

/* Declare the message class */
  //SMTP_Message message;

  /* Set the message headers */
  //mailMessage.sender.name = "Humidity Control Belo Horizonte";
  //mailMessage.sender.email = AUTHOR_EMAIL;
  //mailMessage.subject = "Humidity notification";
  //mailMessage.addRecipient("Christof", RECIPIENT1_EMAIL);
  //mailMessage.addRecipient("Philip", RECIPIENT2_EMAIL);

  Serial.print(F("Waiting for incoming transmission ... "));

  //Serial.println(index_html);

// init filesystem
     if(!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED)){
        Serial.println("LittleFS Mount Failed");
        return;
  }

  Serial.println("Informationen zum Dateisystem:");
  Serial.printf("- Bytes total:   %ld\n", LittleFS.totalBytes());
  Serial.printf("- Bytes genutzt: %ld\n\n", LittleFS.usedBytes());

  readParamFromFile(LittleFS,BACKUPFILE);
  readCalibrationFromFile(LittleFS,CALIBFILE);

//sendMailWithConfigAttachment("Actual Settings and Calibrations attached");
}

void loop() {
  ws.cleanupClients();
  ListenToLoRaClient();

if (DoSetSleep == true){
  if (SysTimer_1() == true){
    DoSetSleep = false;
    SetSoilSensorSleep();
  }  
 }

 if (DoRequestCal > 0){
  if (SysTimer_2() == true){
    if (RequestCal[DoRequestCal-1] == true) {
      RequestCal[DoRequestCal-1] = false;
      SetSoilSensorCalibrate(DoRequestCal);
      DoRequestCal = 0;
    }
  }  

 }

  if (DoSetRelayState == true){ //for BELO setup
    DoSetRelayState = false;
    SetRelayState();
    ResetSysTimer_1();
    DoSetSleep = true;
  }

  if (DoStartIrrigation > 0){ // for HERRLIBERG setup
    StartIrrigation(DoStartIrrigation);
    DoRequestCal = DoStartIrrigation;   //reply with requestcal if sensor is active.
    ResetSysTimer_2();
    DoStartIrrigation = 0;
    ResetSysTimer_1();
    DoSetSleep = true;
  }

  LoRaMessageToScreen(1);

/*    Serial.print("OAT Status: " );
      Serial.println(OATupdateReady);
      Serial.print("FileName: " );
      Serial.println(OATfile);
*/

  if (shouldReboot) {
    rebootESP("Web Admin Initiated Reboot");
  }

**** Code using eMail functionality ***** from sensors

void CalculateRelayState(int S, float H, float T) {

#ifdef BELO

//Relay 1 -> Sensor 1+2
//Relay 2 -> Sensor 3+4
//Relay 3 -> Sensor 5+6
int ActualRelay = 0;
bool RelayState = false;
bool OldRelayState = false;
bool DryState = false;
bool OldDryState = false;

if (S == 1 || S == 2){
  ActualRelay = 1;
}else if (S == 3 || S == 4){
  ActualRelay = 2;
}else if (S == 5 || S == 6){
  ActualRelay = 3;
}

if (ActualRelay == 0){
  Serial.println("Relay AutoSet failed.");
  return;  
}

// HumidityTrigger in Percent [60], Hysteresis as +/-

  if (H >= (HumidityWet[S-1] + HumidityHysteresis) ) {
    RelayState = true;
  }
  if (H <= (HumidityWet[S-1] + HumidityHysteresis) ) {
    RelayState = false;
  }
  if (H >= (HumidityDry[S-1] + HumidityHysteresis) ) {
    DryState = false;
  }
  if (H <= (HumidityDry[S-1] + HumidityHysteresis) ) {
    DryState = true;
  }

  OldRelayState = RelayManualSet[ActualRelay-1];
  RelayManualSet[ActualRelay-1] = RelayState; //set irrigation, 0 = on, 1 = off

  OldDryState = HumidityDryState[S]; 
  HumidityDryState[S] = DryState;

if (OldRelayState != RelayState ){
  String MailMessage = "**** Relay State changed ****\r\n";
  MailMessage += "Soil sensor # " + String(S) + " returned a value of " + String(H) + "% (limiter set to " + String(HumidityWet[S-1) + "%)\r\n";
  MailMessage += "Relay " + String(ActualRelay) + " set to " + String(RelayState)+ " from "+String(OldRelayState) + "\r\n";
  SendMail(MailMessage);
}
if (OldDryState != DryState  ){
  String MailMessage = "**** Humidity Low ****\r\n";
  MailMessage += "Soil sensor # " + String(S) + " returned a value of " + String(H) + "% (Dry limiter set to " + String(HumidityDry[S-1]) + "%)\r\n";
  MailMessage += "Relay " + String(ActualRelay) + " set to " + String(RelayState)+ " from "+String(OldRelayState) +"\r\n";
  MailMessage += "Check Irrigation System.";
  SendMail(MailMessage);
}

  DoSetRelayState = true;
#endif  

#ifdef HERRLIBERG
//R1 Channel 1 -> Sensor 1
//...
//R1 Channel 4 -> Sensor 4

//R2 Channel 1 -> Sensor 5
//...
//R3 Channel 4 -> Sensor 8

int ActualRelay = 0;
int ActualChannel = 0 ;
String MailMessage = "";
String WsClientMessage ="undefined";

if (S >= 1 && S <= 4){
  ActualRelay = 1;
  ActualChannel = S;
}else if (S >= 5 || S <= 8){
  ActualRelay = 2;
  ActualChannel = S - 4;
} 

if (ActualRelay == 0){
  Serial.println("Relay AutoSet failed.");
  return;  
}

// HumidityTrigger in Percent [60], Hysteresis as +/-
  //Start Irrigation
  if (H < HumidityDry[S-1] ) {
    SoilSensorData[S-1].irrigate = true;
  }
  //Send Mail Message
  if (H < (HumidityDry[S-1] - HumidityHysteresis) ) {
    HumidityDryState[S-1] = true; 
  }
  //Stop Irrigation
  if (H > HumidityWet[S-1])  {
    SoilSensorData[S-1].irrigate = false;
  }
 //Send Mail Message
 if (H > (HumidityWet[S-1]+ HumidityHysteresis))  {
    HumidityWetState[S-1] = true;
  }
  //Reset Mail states
  if ( H >= (HumidityDry[S-1] - HumidityHysteresis) && H <= (HumidityWet[S-1] + HumidityHysteresis) ) {
      //H im grünen Bereich  
    HumidityWetState[S-1] = false;
    HumidityDryState[S-1] = false;  
    InfoHumidityMailSent[S-1] = false; 
  }
  if ( T >= TemperatureLow[S-1] && T <= TemperatureHigh[S-1] ) {
      //T im grünen Bereich  
    InfoTemperatureMailSent[S-1] = false; 
  }

DoStartIrrigation = S; //

MailMessage = "";
mailMessage.subject = "Humidity notification";
if ( HumidityWetState[S-1] && NotifyAlert[1] == "1" ){
  MailMessage += "**** Maximum humidity reached ****\r\n";
  MailMessage += "Soil sensor # " + String(S) + " returned a humidity of " + String(H) + "% (Wet limiter set to " + String(HumidityWet[S-1]) + "%)\r\n";
  MailMessage += "Relay " + String(ActualRelay) + " Channel " + String(ActualChannel) + " set to " + String(SoilSensorData[S-1].irrigate) + "\r\n";
  MailMessage += "Pausing irrigation.";
  MailMessage += "\r\n";
}

if ( HumidityDryState[S-1] && NotifyAlert[0] == "1"){
  MailMessage += "**** Minimum humidity reached ****\r\n";
  MailMessage += "Soil sensor # " + String(S) + " returned a humidity of " + String(H) + "% (Dry limiter set to " + String(HumidityDry[S-1]) + "%)\r\n";
  MailMessage += "Relay " + String(ActualRelay) + " Channel " + String(ActualChannel)+ " set to " + String(SoilSensorData[S-1].irrigate) +"\r\n";
  MailMessage += "Starting irrigation.";
  MailMessage += "\r\n";
}
if (MailMessage != ""){
  if (!InfoHumidityMailSent[S-1])  {
    //InfoHumidityMailSent[S-1] = true;
    if (SendMail(MailMessage)){
      Serial.println("Sending Humidity Message sent");
      ws.textAll( "eMail status: S" + String(S) +" -> Sensor Humidity Message sent" );
    } else {
      Serial.println("Sending Humidity Message failed");
      ws.textAll( "eMail status: S" + String(S) +" -> Sensor Humidity Message failed" );
      InfoHumidityMailSent[S-1] = false;
    }
  }
}

MailMessage = "";
mailMessage.subject = "Temperature notification";
if ( T > TemperatureHigh[S-1] && NotifyAlert[3] == "1"){
  MailMessage += "**** Maximum Temperature reached ****\r\n";
  MailMessage += "Temperature of sensor # " + String(S) + " returned a temperature of " + String(T) + "C (Temperature limiter set to " + String(TemperatureHigh[S-1]) + "C)\r\n";
  MailMessage += "Check ventilation if the sensor is in a confined space.";
  MailMessage += "\r\n";
  TemperatureHighState[S-1] = true;
}

if ( T < TemperatureLow[S-1]&& NotifyAlert[2] == "1" ){
  MailMessage += "**** Minimum Temperature reached ****\r\n";
  MailMessage += "Temperature of sensor # " + String(S) + " returned a value of " + String(T) + "C (Temperature limiter set to " + String(TemperatureLow[S-1]) + "C)\r\n";
  MailMessage += "Check heating if the sensor is in a confined space or move plants inside.";
  MailMessage += "\r\n";
  TemperatureLowState[S-1] = true;
}

if (MailMessage != ""){
  if (!InfoTemperatureMailSent[S-1])  {
    InfoTemperatureMailSent[S-1] = true;
    if (SendMail(MailMessage)){
      Serial.println("Sending Temperature Message sent");
      ws.textAll( "eMail status: S" + String(S) +" -> Sensor Temperature Message sent" );
    } else {
      Serial.println("Sending Temperature Message failed");
      ws.textAll( "eMail status: S" + String(S) +" -> Sensor Temperature Message failed" );
      InfoTemperatureMailSent[S-1] = false;
    }
  }
}

DoStartIrrigation = S;

#endif

} 

**** Code using eMail functionality ***** from web interface

void handleWebSocketMessage(void *arg, uint8_t *data, size_t len, int clientId) {
  AwsFrameInfo *info = (AwsFrameInfo*)arg;

  String WsClientMessage;
  String cWs = (char*)data;
  int ElementCounter = 0;

  if (info->final && info->index == 0 && info->len == len && info->opcode == WS_TEXT) {
    data[len] = 0;
    Serial.print("Message from WebClient: ");
    Serial.println((char*)data);
    cWs = CheckForValidASCII(cWs);
    //WsClientMessage = cWs;

  if (cWs.substring(0,6) == "toggle")  {
     int RelayChannel =cWs.substring(6,7).toInt() ;
     RelayChannel = constrain(RelayChannel,1,8) - 1;
     int Rstate = RelayManualSet[RelayChannel];
     if (Rstate == 0){
         RelayManualSet[RelayChannel] = 1;
      } else if (Rstate == 1) {
         RelayManualSet[RelayChannel] = 0;
      } 
      RelayManualOverwrite = true;
      #ifdef BELO
      DoSetRelayState = true;
      #endif
      #ifdef HERRLIBERG
      DoStartIrrigation = RelayChannel + 1;
      #endif
      return;
    }  

    if (cWs.substring(0,2)=="P1"){
      // Check for Parameter Transmission from WS

        //var c = 'P1;'+wlim.value +';'+dlim.value +';'+hys.value +';'+freq.value+';'+itim.value+';'+temph.value+';'+templ.value ;

        int n = 0;
        int i = 0;

        n= cWs.indexOf(";") ; //ersten ; suchen

        i= n+1;
        n= cWs.indexOf(";",i); //zweiten ; suchen
        HumidityWetTrigger = constrain( cWs.substring(i,n).toInt(), 20,80) ; 

        i = n+1;
        n= cWs.indexOf(";",i); //dritten ; suchen
        HumidityDryTrigger = constrain( cWs.substring(i,n).toInt(), 10,30) ;

        i = n+1;
        n= cWs.indexOf(";",i); //viertun ; suchen
        HumidityHysteresis = constrain( cWs.substring(i,n).toInt(), 2,10) ;

        i = n+1;
        n= cWs.indexOf(";",i); //fünften ; suchen
        SoilSensorSleep = constrain( cWs.substring(i,n).toInt(), 1, 408) ; 

        i = n+1;
        n= cWs.indexOf(";",i); //fünften ; suchen
        IrrigationTimer = constrain( cWs.substring(i,n).toInt(), 30, 300) ; 

        i = n+1;
        n= cWs.indexOf(";",i); //fünften ; suchen
        TemperatureHighTrigger = constrain( cWs.substring(i,n).toInt(), 20, 50) ; 

        i = n+1;
        TemperatureLowTrigger = constrain( cWs.substring(i).toInt(), 0, 20) ; 

        //notify all clients
        WsClientMessage = "P1;" + String(HumidityWetTrigger) + ";" + String(HumidityDryTrigger) + ";" + String(HumidityHysteresis)  + ";" + String(SoilSensorSleep )+ ";" + String(IrrigationTimer ) + ";" + String(TemperatureHighTrigger )+ ";" + String(TemperatureLowTrigger )  ;
        //ws.textAll(WsClientMessage); 

        DoSetSleep = true;
        //saveParamToFile(LittleFS,BACKUPFILE);

      } 

      if (cWs.substring(0,2)=="P2"){
        ElementCounter = Split(cWs, ";");
        NotificationSetting = SplitString[1];
        WsClientMessage = "P2;" + NotificationSetting;
        for (int i = 1; i < 4; i++){
          //Index 2,4,6
          NotifyMail[i-1] = SplitString[2*i];
          //Index 3,5,7
          NotificationMail[i-1] = SplitString[2*i +1];
        }
        for (int i = 0; i < 4; i++){
          //Index 8,9,10
          NotifyAlert[i] = SplitString[i+8]; // 0-3 = 8-11
        }

        for (int i = 0; i < 3; i++){
          WsClientMessage += ";" + NotifyMail[i];
          WsClientMessage += ";" + NotificationMail[i];
        }
        for (int i = 0; i < 4; i++){
          WsClientMessage += ";" + NotifyAlert[i];
        }

        // //preparing History
        // int i = nTS.size();
        // String c = "**** Soil Sensor Data History  ";
        // c = c + "Total ";
        // c = c + String(i);
        // c = c + " records ****" + CR + LF + LF ;

        // for (int n = 0; n < i; n++){
        //   c = c + nTS[n] + " " + String(nHS[n]) + " " + String(aHS[n])+ " " + String(bHS[n]) + " " + String(cHS[n])+ " " + String(dHS[n]) +CR+LF;
        // }
        // c = c + LF + "**** End of History ****" + CR +LF;  
        // //Serial.print(c);
        // SendMail(c);

      }

      if (cWs.substring(0,2)=="P3"){
        WsClientMessage = "P3";
        ElementCounter = Split(cWs, ";");
        for (int i = 0; i < MAXSENSORS; i++){
          SensorNames[i] = SplitString[i + 1];
          WsClientMessage += ";" + SensorNames[i]; 
        }
      } 

      if (cWs.substring(0,2)=="P6") {
        // "P6";"S1";"10" Sensor, cal request, itertions
        ElementCounter = Split(cWs, ";");
        int sensor = constrain( SplitString[1].substring(1,2).toInt(), 1, 8) ; 
        SensorCalIterations = SplitString[ElementCounter-1].toInt();
        //RequestCal[sensor-1] = true; // mark for next transmission
        WsClientMessage = "P6" ;
          for (int i = 0; i < MAXSENSORS; i++){
            if (i+1 == sensor){  
              if ( RequestCal[sensor-1]){
                RequestCal[sensor-1] = false;
                WsClientMessage += ";0";
              } else {
                RequestCal[sensor-1] = true;
                WsClientMessage += ";1";
              }
            } else {
              if ( RequestCal[i]){
                WsClientMessage += ";1";
              } else {
                WsClientMessage += ";0";
              }
            }
          }
          ws.textAll(WsClientMessage);
          return; 
      }

      if (cWs.substring(0,2)=="P7"){
        WsClientMessage = "undefined";
        String SaveMailSettings[3];
        String SaveOutput = NotificationSetting; 
        NotificationSetting = "Mail";
        ElementCounter = Split(cWs, ";");
        //History
        //SplitString[1]
        //Configuration
        //SplitString[2]
        //Show Chart
        //SplitString[3]
        //Mail 1
        //SplitString[4]
        //Mail 2 
        //SplitString[5]
        //Mail 3
        //SplitString[6]

        for (int i = 0; i < 3; i++){
          SaveMailSettings[i] = NotifyMail[i];
          NotifyMail[i] = SplitString[i+4];
        }

        if (SplitString[1] == "1" && SplitString[2]=="0"){
          saveHistoryToFile(LittleFS,HISTORYFILE);
          String c = "**** History data attached ****  ";
          if (!sendMailWithAttachment(c, false, true )){
             Serial.println("Sending History Data failed");
             WsClientMessage = "P7->History Data send failed";
          } else {
             WsClientMessage = "P7->History Data successful sent";
          } 
        }
        if (SplitString[1]=="0" && SplitString[2] == "1"){
          String c = "**** Configuration data attached ****  ";
          if (!sendMailWithAttachment(c, true, false )){
             Serial.println("Sending Config Data failed");
             WsClientMessage = "P7->Config Data send failed";
          } else {
             WsClientMessage = "P7->Config Data successful sent";
          } 
        }
            if (SplitString[1] == "1" && SplitString[2]=="1"){
          saveHistoryToFile(LittleFS,HISTORYFILE);
          String c = "**** History and Configuration data attached ****  ";
          if (!sendMailWithAttachment(c, true, true )){
            Serial.println("Sending History and Configuration data failed");
            WsClientMessage = "P7->History and Config Data send failed";
          } else {
             WsClientMessage = "P7->History and Config Data successful sent";
          } 
        }
        //restore mail settings
        for (int i = 0; i < 3; i++){
          NotifyMail[i]=SaveMailSettings[i];
        }
        NotificationSetting = SaveOutput; 
        ws.text(clientId,WsClientMessage);
        return;
      }

      if (cWs.substring(0,2)=="P8"){
        int n = 0;
        ElementCounter = Split(cWs, ";");  
        n = SplitString[2].toInt();
        n = constrain(n,1,8);
        WsClientMessage = prepareChartData(n);
        ws.text(clientId,WsClientMessage);
        return;
      }

      if (cWs.substring(0,8)=="PSaveLim") { //Saving Limiters
          String c = cWs;   
          int nlines = 0;
          int nelements = 0;
      int i = 0;
          //Serial.printf("Lese Backup Datei: %s\r\n", path);
          nlines = Split(c, ";");
          String lines[nlines];
          for (int i = 0; i < nlines; i++) {
            Serial.println("Msg line " +String(i) + " " + SplitString[i]);
            SplitString[i] = CheckForValidASCII(SplitString[i]);
            lines[i] = SplitString[i]; 
          }
          for (int i = 1; i < nlines; i++) {  //without PSaveLim Element
            nelements =  Split(lines[i], ",");

            if (SplitString[0] == "P4") {
              for (int i = 0; i < nelements-1; i++) {
                SensorWater[i] = SplitString[i+1].toInt();
              }
            } else if (SplitString[0] == "PHL") {
              for (int i = 0; i < nelements-1; i++) {
                HumidityDry[i] = SplitString[i+1].toInt();
              }
            }   else if (SplitString[0] == "PHH") {
              for (int i = 0; i < nelements-1; i++) {
                HumidityWet[i] = SplitString[i+1].toInt();
              }
            }  else if (SplitString[0] == "PTL") {
              for (int i = 0; i < nelements-1; i++) {
                TemperatureLow[i] = SplitString[i+1].toInt();
              }
            }   else if (SplitString[0] == "PTH") {
              for (int i = 0; i < nelements-1; i++) {
                TemperatureHigh[i] = SplitString[i+1].toInt();
              }
            }   
          }
          //Check Validity before saving
          WsClientMessage = "PSaveLim;P4";
          for (i = 0; i < MAXSENSORS; i++){
             WsClientMessage += "," + String(SensorWater[i]);
          }

          WsClientMessage += ";PHL";
          for (i = 0; i < MAXSENSORS; i++){
             WsClientMessage += "," + String(HumidityDry[i]);
          }

          WsClientMessage += ";PHH";
          for (i = 0; i < MAXSENSORS; i++){
             WsClientMessage += "," + String(HumidityWet[i]);
          }

          WsClientMessage += ";PTL";
          for (i = 0; i < MAXSENSORS; i++){
             WsClientMessage += "," + String(TemperatureLow[i]);
          }

          WsClientMessage += ";PTH";
          for (i = 0; i < MAXSENSORS; i++){
             WsClientMessage += "," + String(TemperatureHigh[i]);
          }
          //WsClientMessage += ";end";
      cWs = cWs.substring(0, cWs.lastIndexOf(";")); //Remove questionable add ons from original string from WS Client
      }

      if ( cWs != WsClientMessage) {

          ws.textAll("Difference in data, restore last save :");  
          ws.textAll("Input:  " + cWs);  
          ws.textAll("Output: " + WsClientMessage );
          readParamFromFile(LittleFS,BACKUPFILE);
          UpdateWebClient(clientId);

      } else {
          ws.textAll(WsClientMessage); 
          saveParamToFile(LittleFS,BACKUPFILE);
      }

   }

}

***SMTP Client code***
bool SendMail(String MailMessage) {  
  int n = 0;
  if (NotificationSetting != "Mail"){
    Serial.println(MailMessage);
    return false;
  } 

  //Send raw text message
  String textMsg = MailMessage; //"Hello World! - Sent from ESP board";
  #ifdef BELO
    mailMessage.sender.name = "Irrigation Control Belo Horizonte";
  #endif
  #ifdef HERRLIBERG
    mailMessage.sender.name = "Irrigation Control Herrliberg";
  #endif

  mailMessage.clearRecipients();
  for (int i = 0; i < 3; i++ ) {
    if( NotifyMail[i] == "1") {
      mailMessage.addRecipient("Mail " + String(i), NotificationMail[i]);
      n++;
    }
  }

if (n == 0) {
  Serial.println("Notification by mail set on, but no mail address checked.") ;
  Serial.println(MailMessage);
  return false; 
}
  //mailMessage.addRecipient("Christof", RECIPIENT1_EMAIL);

  mailMessage.sender.email = AUTHOR_EMAIL;
  mailMessage.subject = "Irrigation notification";
  mailMessage.text.content = textMsg.c_str();
  mailMessage.text.charSet = "us-ascii";
  mailMessage.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit;

  mailMessage.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low;
  mailMessage.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay;

  /* Set the custom message header */
  //mailMessage.addHeader("Message-ID: <abcde.fghij@gmail.com>");

  /* Connect to server with the session config */
   if (!smtp.connected()) {
    if (!smtp.connect(&mailSession))
      //mailMessage.clear(); 
      return false;
  }
  if (!smtp.isLoggedIn())
  {
    Serial.println("\nNot yet logged in.");
  }
  else
  {
    if (smtp.isAuthenticated())
      Serial.println("\nSuccessfully logged in.");
    else
      Serial.println("\nConnected with no Auth.");
  }

  /* Start sending Email and close the session (par3 = true) */
  if (MailClient.sendMail(&smtp, &mailMessage, false)){
      return true;
  } else {
    Serial.println("Error sending Email, " + smtp.errorReason());
      return false;
  }
}

 bool sendMailWithAttachment(String MailMessage, bool config, bool history ){
  int n = 0;
  //Send raw text message
  String textMsg = MailMessage; 

  #ifdef BELO
    mailMessage.sender.name = "Config Data Belo Horizonte";message.enable.chunking = true;

  #endif
  #ifdef HERRLIBERG
    mailMessage.sender.name = "Config Data Herrliberg";
  #endif

  mailMessage.clearRecipients();
  for (int i = 0; i < 3; i++ ) {
    if( NotifyMail[i] == "1") {
      mailMessage.addRecipient("Mail " + String(i), NotificationMail[i]);
      n++;
    }
  }

if (n == 0) {
  Serial.println("Notification by mail set on, but no mail address checked.") ;
  Serial.println(MailMessage);
  return false; 
}

  mailMessage.clearAttachments();

  mailMessage.enable.chunking = true;
  //mailMessage.addRecipient("Christof", RECIPIENT1_EMAIL);
  mailMessage.sender.email = AUTHOR_EMAIL;
  mailMessage.subject = "No Data attachment";
  mailMessage.text.content = textMsg.c_str();
  mailMessage.text.charSet = "us-ascii";
  mailMessage.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit;

  mailMessage.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low;
  mailMessage.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay;

if (config) {
  mailMessage.resetAttachItem(MailAtt);
  mailMessage.subject = "Data attachment";
  MailAtt.descr.filename = "backup.txt";
  MailAtt.descr.mime = "/"; //binary data
  MailAtt.file.path = BACKUPFILE;
  MailAtt.file.storage_type = esp_mail_file_storage_type_flash;
  MailAtt.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64;

  /* Add attachment to the message */
  mailMessage.addAttachment(MailAtt);

  mailMessage.resetAttachItem(MailAtt);
  MailAtt.descr.filename = "calib.txt";
  MailAtt.descr.mime = "/";
  MailAtt.file.path = CALIBFILE;
  MailAtt.file.storage_type = esp_mail_file_storage_type_flash;
  MailAtt.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64;

  /* Add attachment to the message */
  mailMessage.addAttachment(MailAtt);
  mailMessage.resetAttachItem(MailAtt);
}

if (history) {
  //mailMessage.resetAttachItem(MailAtt);
  mailMessage.subject = "Data attachment";  
  MailAtt.descr.filename = "history.txt";
  MailAtt.descr.mime = "/"; //binary data
  MailAtt.file.path = HISTORYFILE;
  MailAtt.file.storage_type = esp_mail_file_storage_type_flash;
  MailAtt.descr.transfer_encoding = Content_Transfer_Encoding::enc_base64;

  /* Add attachment to the message */
  mailMessage.addAttachment(MailAtt);   
  mailMessage.resetAttachItem(MailAtt);
}

  /* Set the custom message header */
  //mailMessage.addHeader("Message-ID: <abcde.fghij@gmail.com>");

  /* Connect to server with the session config */
  if (!smtp.connected()) {
    if (!smtp.connect(&mailSession))
      //mailMessage.clear(); 
      return false;
  }
  if (!smtp.isLoggedIn())
  {
    Serial.println("\nNot yet logged in.");
  }
  else
  {
    if (smtp.isAuthenticated())
      Serial.println("\nSuccessfully logged in.");
    else
      Serial.println("\nConnected with no Auth.");
  }

  /* Start sending Email and close the session */
  if (!MailClient.sendMail(&smtp, &mailMessage, false)){
    Serial.println("Error sending Email, " + smtp.errorReason());
    mailMessage.clear(); 
      return false;
  } else {
    return true;
  }
}

/* Callback function to get the Email sending status */
void smtpCallback(SMTP_Status status)
{
  /* Print the current status */
  Serial.println(status.info());

  /* Print the sending result */
  if (status.success())
  {
    // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port
    // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266.
    // In ESP8266 and ESP32, you can use Serial.printf directly.

    Serial.println("----------------");
    ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount());
    ESP_MAIL_PRINTF("Message sent failed: %d\n", status.failedCount());
    Serial.println("----------------\n");

    for (size_t i = 0; i < smtp.sendingResult.size(); i++)
    {
      /* Get the result item */
      SMTP_Result result = smtp.sendingResult.getItem(i);

      // In case, ESP32, ESP8266 and SAMD device, the timestamp get from result.timestamp should be valid if
      // your device time was synched with NTP server.
      // Other devices may show invalid timestamp as the device time was not set i.e. it will show Jan 1, 1970.
      // You can call smtp.setSystemTime(xxx) to set device time manually. Where xxx is timestamp (seconds since Jan 1, 1970)
      time_t ts = (time_t)result.timestamp;

      ESP_MAIL_PRINTF("Message No: %d\n", i + 1);
      ESP_MAIL_PRINTF("Status: %s\n", result.completed ? "success" : "failed");
      ESP_MAIL_PRINTF("Date/Time: %s\n", asctime(localtime(&ts)));
      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();

    // Collect memory info
    heapInfo.collect();

    // Print memory info
    heapInfo.print(); 
    mailMessage.clear();

  } 

  // Collect memory info
    heapInfo.collect();

  // Print memory info
    heapInfo.print();

}

**Additional information and things you've tried:**
I tried a lot of tings. requesting the stage of smtp and closing it manually, keeping the connection open, clearing stuff ect.

**** some Logfiles below ***** logs are reduced to ESP-Mail-Client logs

#### Current: 197760, Min: 197760, Max: 197760, Diff_1: 0, Diff_1: 0
> C: ESP Mail Client v3.1.4
> C: connecting to SMTP server
> C: Host > smtp.gmail.com
> C: Port > 587

#### SMTP server connected
#### Heap Info
#### Current: 196912, Min: 196912, Max: 197760, Diff_1: -848, Diff_2: -848
> C: SMTP server connected, wait for greeting...
< S: 220 smtp.gmail.com ESMTP y16-20020a5d4ad0000000b002d51d10a3fasm27333623wrs.55 - gsmtp

#### Sending greeting response...
#### Heap Info
#### Current: 195328, Min: 195328, Max: 197760, Diff_1: -2432, Diff_3: -1584
> C: send SMTP command, HELO
< S: 250-smtp.gmail.com at your service, [185.110.186.41]
< S: 250-SIZE 35882577
< S: 250-8BITMIME
< S: 250-STARTTLS
< S: 250-ENHANCEDSTATUSCODES
< S: 250-PIPELINING
< S: 250-CHUNKING
< S: 250 SMTPUTF8

#### Sending STARTTLS command...
#### Heap Info
#### Current: 195356, Min: 195328, Max: 197760, Diff_1: -2404, Diff_4: 28
> C: send command, STARTTLS
< S: 220 2.0.0 Ready to start TLS
> C: perform SSL/TLS handshake

> C: SSL/TLS negotiation
> 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: perform the SSL/TLS handshake
> C: verifying peer X.509 certificate

#### Sending greeting response...
#### Heap Info
#### Current: 152432, Min: 152432, Max: 197760, Diff_1: -45328, Diff_5: -42924
> C: send SMTP command, HELO
< S: 250-smtp.gmail.com at your service, [185.110.186.41]
< 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...
#### Heap Info
#### Current: 152608, Min: 152432, Max: 197760, Diff_1: -45152, Diff_6: 176
> C: send SMTP command, AUTH PLAIN
> C: esp32.belo@gmail.com
> C: ****************
< S: 235 2.7.0 Accepted

Successfully logged in.

#### Sending Email...
#### Heap Info
#### Current: 152692, Min: 152432, Max: 197760, Diff_1: -45068, Diff_7: 84
> C: send Email

#### Sending message header...
#### Heap Info
#### Current: 152684, Min: 152432, Max: 197760, Diff_1: -45076, Diff_8: -8
> C: send message header
< S: 250 2.1.0 OK y16-20020a5d4ad0000000b002d51d10a3fasm27333623wrs.55 - gsmtp
< S: 250 2.1.5 OK y16-20020a5d4ad0000000b002d51d10a3fasm27333623wrs.55 - gsmtp

#### Sending message body...
#### Heap Info
#### Current: 152348, Min: 152348, Max: 197760, Diff_1: -45412, Diff_9: -336
> C: send message body
< S: 354  Go ahead y16-20020a5d4ad0000000b002d51d10a3fasm27333623wrs.55 - gsmtp

#### Finishing the message sending...
#### Heap Info
#### Current: 148992, Min: 148992, Max: 197760, Diff_1: -48768, Diff_10: -3356
> C: finishing the message sending
< S: 250 2.0.0 OK  1680109086 y16-20020a5d4ad0000000b002d51d10a3fasm27333623wrs.55 - gsmtp

#### -------------------------
#### Heap Info
#### Current: 151272, Min: 148992, Max: 197760, Diff_1: -46488, Diff_11: 2280
#### Message sent success: 1
#### Heap Info
#### Current: 151280, Min: 148992, Max: 197760, Diff_1: -46480, Diff_12: 8
#### Message sent failed: 0
#### Heap Info
#### Current: 151288, Min: 148992, Max: 197760, Diff_1: -46472, Diff_13: 8
#### -------------------------
#### Heap Info
#### Current: 151280, Min: 148992, Max: 197760, Diff_1: -46480, Diff_14: -8
#### Status: success
#### Heap Info
#### Current: 151292, Min: 148992, Max: 197760, Diff_1: -46468, Diff_15: 12
#### Date/Time: Wed Mar 29 18:58:06 202
#### Heap Info
#### Current: 151168, Min: 148992, Max: 197760, Diff_1: -46592, Diff_16: -124
#### Recipient: christof.schmid@aaa-immobilien.ch
#### Heap Info
#### Current: 151144, Min: 148992, Max: 197760, Diff_1: -46616, Diff_17: -24
#### Subject: Irrigation notification
#### Heap Info
#### Current: 151168, Min: 148992, Max: 197760, Diff_1: -46592, Diff_18: 24
Sending Humidity Message sent

**** next attempt ******

Successfully logged in.

#### Sending next Email...
#### Heap Info
#### Current: 149916, Min: 148992, Max: 197760, Diff_1: -47844, Diff_19: -1252
> C: send next Email

#### Sending message header...
#### Heap Info
#### Current: 149912, Min: 148992, Max: 197760, Diff_1: -47848, Diff_20: -4
> C: send message header
#### Error, connection closed
#### Heap Info
#### Current: 148864, Min: 148864, Max: 197760, Diff_1: -48896, Diff_21: -1048
! E: connection closed

#### -------------------------
#### Heap Info
#### Current: 148288, Min: 148288, Max: 197760, Diff_1: -49472, Diff_22: -576
#### Message sent success: 1
#### Heap Info
#### Current: 151636, Min: 148288, Max: 197760, Diff_1: -46124, Diff_23: 3348
#### Message sent failed: 1
#### Heap Info
#### Current: 151636, Min: 148288, Max: 197760, Diff_1: -46124, Diff_24: 0
#### -------------------------
#### Heap Info
#### Current: 151636, Min: 148288, Max: 197760, Diff_1: -46124, Diff_25: 0
#### Status: failed
#### Heap Info
#### Current: 151648, Min: 148288, Max: 197760, Diff_1: -46112, Diff_26: 12
#### Date/Time: Wed Mar 29 18:58:06 202
#### Heap Info
#### Current: 151624, Min: 148288, Max: 197760, Diff_1: -46136, Diff_27: -24
#### Recipient: christof.schmid@aaa-immobilien.ch
#### Heap Info
#### Current: 151600, Min: 148288, Max: 197760, Diff_1: -46160, Diff_28: -24
#### Subject: Irrigation notification
#### Heap Info
#### Current: 151624, Min: 148288, Max: 197760, Diff_1: -46136, Diff_29: 24
Error sending Email, connection closed
Sending Humidity Message failed

*************next attempt ****************
#### Connecting to SMTP server...
#### Heap Info
#### Current: 152452, Min: 148288, Max: 197760, Diff_1: -45308, Diff_30: 828
> C: ESP Mail Client v3.1.4
> C: connecting to SMTP server
> C: Host > smtp.gmail.com
> C: Port > 587

#### SMTP server connected
#### Heap Info
#### Current: 153348, Min: 148288, Max: 197760, Diff_1: -44412, Diff_31: 896
> C: SMTP server connected, wait for greeting...
< S: 220 smtp.gmail.com ESMTP t13-20020adfe10d000000b002db1b66ea8fsm17236522wrz.57 - gsmtp

#### Sending greeting response...
#### Heap Info
#### Current: 151848, Min: 148288, Max: 197760, Diff_1: -45912, Diff_32: -1500
> C: send SMTP command, HELO
< S: 250-smtp.gmail.com at your service, [185.110.186.41]
< S: 250-SIZE 35882577
< S: 250-8BITMIME
< S: 250-STARTTLS
< S: 250-ENHANCEDSTATUSCODES
< S: 250-PIPELINING
< S: 250-CHUNKING
< S: 250 SMTPUTF8

#### Sending STARTTLS command...
#### Heap Info
#### Current: 152016, Min: 148288, Max: 197760, Diff_1: -45744, Diff_33: 168
> C: send command, STARTTLS
< S: 220 2.0.0 Ready to start TLS
> C: perform SSL/TLS handshake

> C: SSL/TLS negotiation
> 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: perform the SSL/TLS handshake
> C: verifying peer X.509 certificate
#### Sending greeting response...
#### Heap Info
#### Current: 115928, Min: 115928, Max: 197760, Diff_1: -81832, Diff_34: -36088
> C: send SMTP command, HELO
[1117242][E][ESP32_SSL_Client.cpp:63] _esp32_ssl_handle_error(): [send_ssl_data():545]: (-27136) SSL - A buffer is too small to receive or write a message
> C: cleaning SSL connection
#### Error, data sending failed
#### Heap Info
#### Current: 162208, Min: 115928, Max: 197760, Diff_1: -35552, Diff_35: 46280
! E: data sending failed
Sending Humidity Message failed

****** next atempt ************
> C: ESP Mail Client v3.1.4
> C: connecting to SMTP server
> C: Host > smtp.gmail.com
> C: Port > 587

#### SMTP server connected
#### Heap Info
#### Current: 162236, Min: 115928, Max: 197760, Diff_1: -35524, Diff_37: -604
> C: SMTP server connected, wait for greeting...
< S: 220 smtp.gmail.com ESMTP n17-20020adff091000000b002c5534db60bsm30742543wro.71 - gsmtp

#### Sending greeting response...
#### Heap Info
#### Current: 160720, Min: 115928, Max: 197760, Diff_1: -37040, Diff_38: -1516
> C: send SMTP command, HELO
< S: 250-smtp.gmail.com at your service, [185.110.186.41]
< S: 250-SIZE 35882577
< S: 250-8BITMIME
< S: 250-STARTTLS
< S: 250-ENHANCEDSTATUSCODES
< S: 250-PIPELINING
< S: 250-CHUNKING
< S: 250 SMTPUTF8

#### Sending STARTTLS command...
#### Heap Info
#### Current: 160752, Min: 115928, Max: 197760, Diff_1: -37008, Diff_39: 32
> C: send command, STARTTLS
< S: 220 2.0.0 Ready to start TLS
> C: perform SSL/TLS handshake

> C: SSL/TLS negotiation
> 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: perform the SSL/TLS handshake
> C: verifying peer X.509 certificate
#### Sending greeting response...
#### Heap Info
#### Current: 118280, Min: 115928, Max: 197760, Diff_1: -79480, Diff_40: -42472
> C: send SMTP command, HELO
< S: 250-smtp.gmail.com at your service, [185.110.186.41]
< 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...
#### Heap Info
#### Current: 118068, Min: 115928, Max: 197760, Diff_1: -79692, Diff_41: -212
> C: send SMTP command, AUTH PLAIN
> C: esp32.belo@gmail.com
> C: ****************
< S: 235 2.7.0 Accepted

Successfully logged in.

#### Sending next Email...
#### Heap Info
#### Current: 118348, Min: 115928, Max: 197760, Diff_1: -79412, Diff_42: 280
> C: send next Email

#### Sending message header...
#### Heap Info
#### Current: 118340, Min: 115928, Max: 197760, Diff_1: -79420, Diff_43: -8
> C: send message header
< S: 250 2.1.0 OK n17-20020adff091000000b002c5534db60bsm30742543wro.71 - gsmtp
< S: 250 2.1.5 OK n17-20020adff091000000b002c5534db60bsm30742543wro.71 - gsmtp

#### Sending message body...
#### Heap Info
#### Current: 118012, Min: 115928, Max: 197760, Diff_1: -79748, Diff_44: -328
> C: send message body
< S: 354  Go ahead n17-20020adff091000000b002c5534db60bsm30742543wro.71 - gsmtp

#### Finishing the message sending...
#### Heap Info
#### Current: 114692, Min: 114692, Max: 197760, Diff_1: -83068, Diff_45: -3320
> C: finishing the message sending
< S: 250 2.0.0 OK  1680110078 n17-20020adff091000000b002c5534db60bsm30742543wro.71 - gsmtp
#### -------------------------
#### Heap Info
#### Current: 117148, Min: 114692, Max: 197760, Diff_1: -80612, Diff_46: 2456
#### Message sent success: 2
#### Heap Info
#### Current: 117156, Min: 114692, Max: 197760, Diff_1: -80604, Diff_47: 8
#### Message sent failed: 1
#### Heap Info
#### Current: 117160, Min: 114692, Max: 197760, Diff_1: -80600, Diff_48: 4
#### -------------------------
#### Heap Info
#### Current: 117156, Min: 114692, Max: 197760, Diff_1: -80604, Diff_49: -4
#### Status: success
#### Heap Info
#### Current: 117164, Min: 114692, Max: 197760, Diff_1: -80596, Diff_50: 8
#### Date/Time: Wed Mar 29 19:14:38 202
#### Heap Info
#### Current: 117140, Min: 114692, Max: 197760, Diff_1: -80620, Diff_51: -24
#### Recipient: christof.schmid@aaa-immobilien.ch
#### Heap Info
#### Current: 117104, Min: 114692, Max: 197760, Diff_1: -80656, Diff_52: -36
#### Subject: Irrigation notification
#### Heap Info
#### Current: 117140, Min: 114692, Max: 197760, Diff_1: -80620, Diff_53: 36
Sending Humidity Message sent

***** next attempt **********

Successfully logged in.

#### Sending next Email...
#### Heap Info
#### Current: 116164, Min: 114692, Max: 197760, Diff_1: -81596, Diff_54: -976
> C: send next Email

#### Sending message header...
#### Heap Info
#### Current: 116144, Min: 114692, Max: 197760, Diff_1: -81616, Diff_55: -20
> C: send message header
#### Error, connection closed
#### Heap Info
#### Current: 115124, Min: 114692, Max: 197760, Diff_1: -82636, Diff_56: -1020
! E: connection closed

#### -------------------------
#### Heap Info
#### Current: 114524, Min: 114524, Max: 197760, Diff_1: -83236, Diff_57: -600
#### Message sent success: 2
#### Heap Info
#### Current: 115572, Min: 114524, Max: 197760, Diff_1: -82188, Diff_58: 1048
#### Message sent failed: 2
#### Heap Info
#### Current: 117904, Min: 114524, Max: 197760, Diff_1: -79856, Diff_59: 2332
#### -------------------------
#### Heap Info
#### Current: 117896, Min: 114524, Max: 197760, Diff_1: -79864, Diff_60: -8
#### Status: failed
#### Heap Info
#### Current: 117916, Min: 114524, Max: 197760, Diff_1: -79844, Diff_61: 20
#### Date/Time: Wed Mar 29 19:14:38 202
#### Heap Info
#### Current: 117872, Min: 114524, Max: 197760, Diff_1: -79888, Diff_62: -44
#### Recipient: christof.schmid@aaa-immobilien.ch
#### Heap Info
#### Current: 117856, Min: 114524, Max: 197760, Diff_1: -79904, Diff_63: -16
#### Subject: Irrigation notification
#### Heap Info
#### Current: 117872, Min: 114524, Max: 197760, Diff_1: -79888, Diff_64: 16
Error sending Email, connection closed
Sending Humidity Message failed

**** and so on until ESP-Mail-Client does not even show a single Message on serial...
mobizt commented 1 year ago

Where is "* next attempt " printing on your code?

mobizt commented 1 year ago

Now the library update v3.1.5 with issues fixed is available. Please update.

ChristofSchmid commented 1 year ago

Hi Suwatchai

Thanks a lot for the fix. I had the new build running all day.

When leaving the smtp connection open, after a while there is a disconnect and reconnect which I expected. This caused 2 of 40 messages not sent. ( I guess google disconnected when the send process was in progress or so)

When using the MailClient.sendMail with the param 3 flag true (close option) the lib works flawless, no message skipped.


Message sent success: 44 Message send failed: 0

Thanks again Christof