Refering to this topic (Oct 2025) where the author of this library (@Mobizt ) suggested testing with this example sketch from him:
ReadyMail/examples/Network/AutoClient/AutoClient.ino
This sketch is designed to send emails from authenticated email servers using either SSL (port 465), TLS (port 587) or palin text (port 25).
My webmail server uses port 587, and authentication works well as can be seen in the output from the serial monitor below.
However, more often then not does no email get sent. This erratic behaviour very much puzzles me because I cannot discover any rational explanation for this.
After a suggestion from @Mobizt last year I added this line of code at the end of the sendEmail function:
smtp.stop(); // terminate connection https://forum.arduino.cc/t/readymail-h-example-autoclient-ino-error-sending-starttls-command/1409355/3
Serial monitor output (only those sessions where is shown "The Email is sent successfully" is the email succesfully received. In the monitor output below this was the case in 1 out of 5 or 6 or more sessions.
Connecting to Wi-Fi..................
Connected with IP: 192.168.1.208
ReadyMail, version 0.3.6
ReadyMail[smtp][1] Connecting to "webreus.email" via port 587...
ReadyMail[smtp][2] Sending greeting...
ReadyMail[smtp][3] Starting TLS...
ReadyMail[smtp][3] Performing TLS handshake...
ReadyMail[smtp][3] TLS handshake done
ReadyMail[smtp][2] Sending greeting...
ReadyMail[smtp][2] Service is ready
ReadyMail[smtp][5] Authenticating...
ReadyMail[smtp][5] The client is authenticated successfully
ReadyMail[smtp][11] Sending Email...
ReadyMail[smtp][11] Sending envelope...
ReadyMail[smtp][12] Sending headers...
ReadyMail[smtp][14] Sending multipart content (alternative)...
ReadyMail[smtp][14] Sending text/plain body...
ReadyMail[smtp][14] Sending text/html body...
ReadyMail[smtp][14] The Email is sent successfully
ReadyMail[smtp][20] Stop the TCPsession...
Another session:
Connecting to Wi-Fi........................
Connected with IP: 192.168.1.208
ReadyMail, version 0.3.6
ReadyMail[smtp][1] Connecting to "webreus.email" via port 587...
ReadyMail[smtp][2] Sending greeting...
ReadyMail[smtp][3] Starting TLS...
ReadyMail[smtp][3] Performing TLS handshake...
ReadyMail[smtp][3] TLS handshake done
ReadyMail[smtp][2] Sending greeting...
ReadyMail[smtp][2] Service is ready
ReadyMail[smtp][5] Authenticating...
Another session:
Connected with IP: 192.168.1.208
ReadyMail, version 0.3.6
ReadyMail[smtp][1] Connecting to "webreus.email" via port 587...
ReadyMail[smtp][2] Sending greeting...
ReadyMail[smtp][3] Starting TLS...
ReadyMail[smtp][3] Performing TLS handshake...
ReadyMail[smtp][3] TLS handshake done
ReadyMail[smtp][2] Sending greeting...
ReadyMail[smtp][2] Service is ready
ReadyMail[smtp][5] Authenticating...
ReadyMail[smtp][5] The client is authenticated successfully
ReadyMail[smtp][11] Sending Email...
ReadyMail[smtp][11] Sending envelope...
ReadyMail[smtp][12] Sending headers...
ReadyMail[smtp][14] Sending multipart content (alternative)...
ReadyMail[smtp][14] Sending text/plain body...
ReadyMail[smtp][14] Sending text/html body...type or paste code here
Another session:
Connecting to Wi-Fi...................
Connected with IP: 192.168.1.208
ReadyMail, version 0.3.6
ReadyMail[smtp][1] Connecting to "webreus.email" via port 587...
ReadyMail[smtp][2] Sending greeting...
ReadyMail[smtp][3] Starting TLS...
ReadyMail[smtp][3] Performing TLS handshake...
ReadyMail[smtp][3] TLS handshake done
ReadyMail[smtp][2] Sending greeting...
ReadyMail[smtp][2] Service is ready
ReadyMail[smtp][5] Authenticating...
ReadyMail[smtp][5] The client is authenticated successfully
ReadyMail[smtp][11] Sending Email...
ReadyMail[smtp][11] Sending envelope...
ReadyMail[smtp][12] Sending headers...
ReadyMail[smtp][14] Sending multipart content (alternative)...
ReadyMail[smtp][14] Sending text/plain body...
ReadyMail[smtp][14] Sending text/html body...
The sketch used is the same as used in the example sketch from ReadyMail.h library examples, except that I do not use the Networks.h library, and I also only use port 587 (TLS):
#include <Arduino.h>
// #include "Networks.h"
// #include <WiFiClient.h>
#include <ESP8266WiFi.h>
#define ENABLE_SMTP
#define ENABLE_DEBUG
#define READYMAIL_DEBUG_PORT Serial
#define USE_ESP_SSLCLIENT
#if defined(USE_ESP_SSLCLIENT)
#include <ESP_SSLClient.h>
#else
#include <NetworkClientSecure.h>
#endif
#if defined(USE_ESP_SSLCLIENT)
#define READYCLIENT_SSL_CLIENT ESP_SSLClient
#define READYCLIENT_TYPE_1 // TYPE 1 when using ESP_SSLClient
#else
#define READYCLIENT_SSL_CLIENT NetworkClientSecure
#define READYCLIENT_TYPE_2 // TYPE 2 when using NetworkClientSecure
#endif
#include <ReadyMail.h>
#define SMTP_HOST "____"
#define AUTHOR_EMAIL "____"
#define AUTHOR_PASSWORD "____"
#define RECIPIENT_EMAIL "____"
#define WIFI_SSID "____"
#define WIFI_PASSWORD "____"
#if defined(USE_ESP_SSLCLIENT)
WiFiClient basic_client;
ESP_SSLClient ssl_client;
#else
NetworkClientSecure ssl_client;
#endif
ReadyClient rClient(ssl_client);
SMTPClient smtp(rClient);
// For more information, see http://bit.ly/474niML
void smtpCb(SMTPStatus status)
{
if (status.progress.available)
ReadyMail.printf("ReadyMail[smtp][%d] Uploading file %s, %d %% completed\n", status.state,
status.progress.filename.c_str(), status.progress.value);
else
ReadyMail.printf("ReadyMail[smtp][%d]%s\n", status.state, status.text.c_str());
}
void sendEmail(int port)
{
smtp.connect(SMTP_HOST, port, smtpCb);
if (!smtp.isConnected())
return;
smtp.authenticate(AUTHOR_EMAIL, AUTHOR_PASSWORD, readymail_auth_password);
if (!smtp.isAuthenticated())
return;
SMTPMessage msg;
msg.headers.add(rfc822_subject, "ReadyMail test via port " + String(port));
msg.headers.add(rfc822_from, "ReadyMail <" + String(AUTHOR_EMAIL) + ">");
msg.headers.add(rfc822_to, "User <" + String(RECIPIENT_EMAIL) + ">");
String bodyText = "Hello test.";
msg.text.body(bodyText);
msg.html.body("<html><body><div style=\"color:#cc0066;\">" + bodyText + "</div></body></html>");
msg.timestamp = 1746013620;
smtp.send(msg);
smtp.stop(); // terminate connection https://forum.arduino.cc/t/readymail-h-example-autoclient-ino-error-sending-starttls-command/1409355/3
delay(10);
}
void setup()
{
Serial.begin(115200);
Serial.println();
WiFi.begin(WIFI_SSID, WIFI_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();
#if defined(USE_ESP_SSLCLIENT)
ssl_client.setClient(&basic_client);
#endif
// If server SSL certificate verification was ignored for this SSL Client.
// To verify root CA or server SSL cerificate,
// please consult SSL Client documentation.
ssl_client.setInsecure();
Serial.println("ReadyMail, version " + String(READYMAIL_VERSION));
// rClient.addPort(465, readymail_protocol_ssl);
rClient.addPort(587, readymail_protocol_tls);
// rClient.addPort(25, readymail_protocol_plain_text);
// sendEmail(465); // SSL
sendEmail(587); // STARTTLS
// If your server supports this protocol.
// sendEmail(25); // Plain Text
}
void loop()
{
}
Many thanks in advance for your help,
Erik