Arduino mega 2560 wifi e-mail senden über smtp server

Hallo zusammen ich habe folgende Herausvorderung. Ich bin ein Honigverkaufsautomat am programmieren und ich möchte wenn ein Glas verkauft wird eine Meldung über mail zu bekommen.
Ich verwende ein Arduino MEGA2560 Wifi . Die Verbindung in WLAN funktioniert. Nach dem Verkauf verbindet sich mit dem smtp server und nach dem senden der EHLO Befehl geht in Error.
Über Telnet habe getestet und funktioniert.

250-PIPELINING
250-SIZE 33554432
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 CHUNKING
AUTH LOGIN
334 VXNlcm5hbWU6
SMTP_USER_B64
334 UGFzc3dvcmQ6
SMTP_PASS_B64
235 2.7.0 Authentication successful
MAIL FROM:***********@arcor.de
250 2.1.0 Ok
RCPT TO:************@yahoo.de
250 2.1.5 Ok
DATA
354 End data with .
Subject: Glasverkauf Slot 3
From: *************@arcor.de
To: **************@yahoo.de

Das Glas in Slot 3 wurde verkauft.
.
250 2.0.0 Ok: queued as 4Z5N8j3299z9rw8
quit
221 2.0.0 Bye

Fogende Einstellungen habe für SMTP:

// ===== SMTP Einstellungen =====k

//-------------------arcor-----------------------
#define SMTP_SERVER   "smtp.vodafone.de"
#define SMTP_PORT     587
//#define SMTP_USER     "********@arcor.de"       // Deine  E-Mail-Adresse
//#define SMTP_PASS     "*******"               // Dein Passwort (wird in Base64 gesendet)
#define SMTP_USER_B64 "****************"      // 
#define SMTP_PASS_B64 "**********"      // Base64 deines Passworts 
#define DEST_EMAIL    "************@yahoo.de"         // Zieladresse (wo die Mail ankommen soll)

und hier ist meine Send Routine

void sendSMTPEmail(int slot) {
  Serial.println("Sende SMTP Email...");

  // 1. Verbindung zum SMTP-Server auf Port 587 aufbauen (ohne SSL!)
  String cipstart = "AT+CIPSTART=\"TCP\",\"" + String(SMTP_SERVER) + "\",587";
  espSerial.println(cipstart);
  delay(4000);
  while (espSerial.available()) {
    Serial.println(espSerial.readString());
  }

  // 2. EHLO senden (wichtig für SMTP)
  espSerial.println("EHLO esp8266\r\n");
  delay(4000);
  while (espSerial.available()) {
    Serial.println(espSerial.readString());
  }

  // 3. STARTTLS aktivieren (jetzt wird verschlüsselt!)
  espSerial.println("STARTTLS\r\n");
  delay(4000);
  while (espSerial.available()) {
    Serial.println(espSerial.readString());
  }

  // 4. EHLO nochmal senden, weil STARTTLS die Verbindung neu startet
  espSerial.println("EHLO esp8266\r\n");
  delay(4000);
  while (espSerial.available()) {
    Serial.println(espSerial.readString());
  }

  // 5. AUTH LOGIN initiieren
  espSerial.println("AUTH LOGIN\r\n");
  delay(3500);
  while (espSerial.available()) {
    Serial.println(espSerial.readString());
  }

  // 6. Base64-Benutzername senden
  espSerial.println(String(SMTP_USER_B64) + "\r\n");


  delay(1500);
  while (espSerial.available()) {
    Serial.println(espSerial.readString());
  }

  // 7. Base64-Passwort senden
  espSerial.println(String(SMTP_PASS_B64) + "\r\n");
  delay(1500);
  while (espSerial.available()) {
    Serial.println(espSerial.readString());
  }

  // 8. MAIL FROM-Befehl
  String mailFrom = "MAIL FROM:<" + String(SMTP_USER_B64) + ">\r\n";
  espSerial.println(mailFrom);
  delay(1500);
  while (espSerial.available()) {
    Serial.println(espSerial.readString());
  }

  // 9. RCPT TO-Befehl (Empfänger-Adresse)
  String rcptTo = "RCPT TO:<" + String(DEST_EMAIL) + ">\r\n";
  espSerial.println(rcptTo);
  delay(1500);
  while (espSerial.available()) {
    Serial.println(espSerial.readString());
  }

  // 10. DATA-Befehl – Beginn der Nachricht
  espSerial.println("DATA\r\n");
  delay(1500);
  while (espSerial.available()) {
    Serial.println(espSerial.readString());
  }

  // 11. Email-Inhalt senden
  String emailContent = "";
  emailContent += "Subject: Glasverkauf Slot " + String(slot) + "\r\n";
  emailContent += "From: " + String(SMTP_USER_B64) + "\r\n";
  emailContent += "To: " + String(DEST_EMAIL) + "\r\n";
  emailContent += "\r\n"; // Leerzeile zwischen Header und Body
  emailContent += "Es wurde ein Glas im Slot " + String(slot) + " verkauft.\r\n";
  emailContent += "\r\n.\r\n";  // Ende der DATA-Sektion

  espSerial.print(emailContent);
  delay(3000);
  while (espSerial.available()) {
    Serial.println(espSerial.readString());
  }

  // 12. QUIT-Befehl senden und Verbindung schließen
  espSerial.println("QUIT\r\n");
  delay(1500);
  while (espSerial.available()) {
    Serial.println(espSerial.readString());
  }

  espSerial.println("AT+CIPCLOSE\r\n");
  delay(500);
  Serial.println("SMTP Email Request gesendet.");
}

und hier ist die Ausgabe aus den seriellen Monitor. Nach den EHLO Befehl geht in Error.

:40:23.906 -> Münzwert erkannt: 1.00 Euro

14:40:28.290 -> Sende SMTP Email...

14:40:33.328 -> AT+CIPSTART="TCP","smtp.vodafone.de",587

14:40:33.328 -> CONNECT

14:40:33.328 ->

14:40:33.328 -> OK

14:40:33.328 ->

14:40:33.328 -> +IP

14:40:38.284 -> EHLO esp8266

14:40:38.284 -> ERROR

14:40:38.284 ->

14:40:38.284 -> ERROR

14:40:38.325 ->

14:40:43.329 -> STARTTLS

14:40:43.329 -> ERROR

14:40:43.329 ->

14:40:43.329 -> ERROR

14:40:43.329 ->

14:40:48.307 -> EHLO esp8266

14:40:48.307 -> ERROR

14:40:48.307 ->

14:40:48.329 -> ERROR

14:40:48.329 ->

14:40:52.789 -> AUTH LOGIN

14:40:52.789 -> ERROR

14:40:52.789 ->

14:40:52.789 -> ERROR

14:40:52.789 ->

14:40:55.294 -> ****************** SMTP_USER_B64

14:40:55.329 -> ERROR

14:40:55.329 ->

14:40:55.329 -> ERROR

14:40:55.329 ->

14:40:57.797 -> *************** SMTP_PASS_B64

14:40:57.797 -> ERROR

14:40:57.797 ->

14:40:57.797 -> ERROR

14:40:57.837 ->
14:41:00.325 -> MAIL FROM:<*******************>

14:41:00.325 -> ERROR

14:41:00.325 ->

14:41:00.325 -> ER

14:41:02.828 -> RCPT TO:*************@yahoo.de

14:41:02.828 -> ERROR

14:41:02.828 ->

14:41:02.828 -> ERROR

14:41:02.828 ->

14:41:05.316 -> DATA

14:41:05.316 ->

14:41:05.316 -> busy p...

14:41:05.316 ->

14:41:05.316 -> ERROR

14:41:05.316 ->

14:41:09.310 -> Subject: Glasverkauf Slot 7

14:41:09.310 -> ERROR

14:41:09.343 -> From: *******************

14:41:11.837 -> QUIT

14:41:11.837 -> ERROR

14:41:11.837 ->

14:41:11.837 -> ERROR

14:41:11.837 ->

14:41:12.306 -> SMTP Email Request gesendet.

Hat jemand eine Idee was ich falsch mache?

Gruß......Eddie

Was genau soll das heißen "nach dem Verkauf" ?
Und poste einen Link deines Controllers.

nach dem ein glas honig verkauft wurde.

hier ist der Link:https://de.aliexpress.com/item/1005007359771211.html?srcSns=sns_WhatsApp&spreadType=socialShare&bizType=ProductDetail&social_params=61009221028&aff_fcid=7c2609c0ed414b0b8a7cdb4dbf542db3-1740927188682-04593-_EJdmhVI&tt=MG&aff_fsk=_EJdmhVI&aff_platform=default&sk=_EJdmhVI&aff_trace_key=7c2609c0ed414b0b8a7cdb4dbf542db3-1740927188682-04593-_EJdmhVI&shareId=61009221028&businessType=ProductDetail&platform=AE&terminal_id=bfb6cc0487a242749103f29b431a7ecc&afSmartRedirect=y

Ok, das ist kein Arduino und hat wohl auch nichts mit Honig zu tun.
Ok, habe es jetzt.

Ich tippe darauf, dass dein Provider nicht mit der Anmeldung klar kommt.

Ich verwende am ESP8266 diese Library für den Email-Versand mit 1und1 und das Problemlos. Teste es einfach mal.

Aber in Telnet funktioniert. Brauche ein Sketch für den esp 8266 oder geht das über AT?

Ich sehe in Deinem Telnet-Auszug kein EHLO.
Wenn das Telnet etwas bringen soll, musst Du schon genau das Gleiche senden, wie vom ESP.

Gruß Tommy

Sieh dir das Beispiel im Link an.
Das ist gut beschrieben. Ich habe vor langer Zeit mehrere Libraries getestet und blieb bei dieser hängen, weil die sehr komfortabel ist und auf Anhieb funktionierte.

Hab gerade nochmal in telnet getestet. Wahrscheinlich ist mir ersten mal beim kopieren unter den Teppich gefallen

220 smtp.vodafone.de ESMTP CLMSA
EHLO esp8266
250-smtp.vodafone.de
250-PIPELINING
250-SIZE 33554432
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 CHUNKING
AUTH LOGIN
334 VXNlcm5hbWU6


334 UGFzc3dvcmQ6


235 2.7.0 Authentication successful
MAIL FROM:**************@arcor.de
250 2.1.0 Ok
RCPT TO:**************@yahoo.de
250 2.1.5 Ok
DATA
354 End data with .
Subject: Glasverkauf Slot 4
From: *************@arcor.de
To: ***********@yahoo.de

Das Glas in Slot 4 wurde verkauft.
.
250 2.0.0 Ok: queued as 4Z5RBv6ZMnz8sXh
QUIT
221 2.0.0 Bye

Verbindung zu Host verloren.

Hab das Beispiel aus den link genommen und beim kompilieren bekomme folgenden Fehler
:

In file included from C:\Users\Eddie\AppData\Local\Temp\.arduinoIDE-unsaved202522-2744-i7isn8.xjew\sketch_mar2c\sketch_mar2c.ino:46:0:
c:\Users\Eddie\Documents\Arduino\libraries\ESP_Mail_Client\src/ESP_Mail_Client.h:39:10: fatal error: algorithm: No such file or directory
 #include <algorithm>
          ^~~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: exit status 1

Ich kann mit dem algorithm nichts anfangen. Muss ich noch andere librarys einfügen?

Du musst nur das einbinden, was auch im Beispiel verwendet wird.

du redest von dieses Beispiel oder?

// 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
  }
}


Ja, das meine ich. Du musst das nur an deine Gegebenheiten anpassen.
So einfach wie möglich, um eine Testmail zu versenden.

ja das habe ich.
#include <ESP_Mail_Client.h> muss ich anwenden und die Fehler kommt aus dem ESP_Mail_Client.h

In file included from C:\Users\Eddie\AppData\Local\Temp\.arduinoIDE-unsaved202522-2744-i7isn8.xjew\sketch_mar2c\sketch_mar2c.ino:46:0:
c:\Users\Eddie\Documents\Arduino\libraries\ESP_Mail_Client\src/ESP_Mail_Client.h:39:10: fatal error: algorithm: No such file or directory
 #include <algorithm>
          ^~~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: exit status 1

Welche IDE Version und welche core Version setzt du ein ?

IDE Version 2.3.4

Und welche ESP core Version?

Edit:
Ich verwende die IDE 1.8.19 und core 3.1.2. Damit compiliert er fehlerfrei.
Evtl. ist etwas an deiner Installation fehlerhaft.
Andere Idee habe ich aktuell nicht.

Evtl. den Mail-Client mal auf einem einzelnen ESP8266 Wemos D1 mini installieren und testen. Auf einem Board mit 2 Controllern kann es schon mal zu Problemen kommen.

Jetzt ist mir klar. Ich hab versucht alles zu installieren auf der Mega. Meine ganze Routine läuft auf Mega. Die Übertragung zu Mail ist auch in Der Ino Datei auf Mega. Aber wenn ich jetzt die Routine mache zum senden auf dem ESP 82,66, der in Dem Arduino Bord integriert ist, Wie verheirate ich Die beiden? Sorry, mit der Rechtschreibung ist alles über die Diktierfunktion geschrieben.
Gruß Eddie

Das kann natürlich nicht funktionieren.
Allerdings sollten da ein paar mehr Fehlermeldungen kommen.

Das kannst du per UART (seriell) machen. Dazu verwendest "SoftwareSerial" auf beiden Controllern.
Dann mal die Frage: Wozu überhaupt den Mega ?
Evtl. reicht ja ein ESP8266 oder ESP32 aus.

Hab mit Mega angefangen. Das Gedanken mit mailen Kamm später. Und weil alles schon vorhanden war wollte nicht umsteigen.