I use Wemos D1 mini. I compiled successfuly and installed send_text example, an example part of ESP Mail Client.
While the code is executed I received this error message: Connection error, Status Code: 0, Error Code: -100, Reason: unable to connect to server.
What is wrong ?
The server address is wrong or in the wrong format ?
I used the one declared in the example: smtp.gmail.com
Please post your full sketch
Does your code use a DNS? Did you try to use an IP instead of hostname?
no. GMAIL SMTP server may change its IP (not a fix IP). Anyway' I used the example almost as it, just placed the dummy addresses with mine/
i cahned my personal details. also I tried to use app-password instead of my personal password as explained at the link above the statement of the passowrd needed for connecting the email server.
/**
This example showes how to send text Email.
Created by K. Suwatchai (Mobizt)
Email: suwatchai@outlook.com
Github: https://github.com/mobizt/ESP-Mail-Client
Copyright (c) 2023 mobizt
*/
/** ////////////////////////////////////////////////
Struct data names changed from v2.x.x to v3.x.x
////////////////////////////////////////////////
"ESP_Mail_Session" changes to "Session_Config"
"IMAP_Config" changes to "IMAP_Data"
Changes in the examples
ESP_Mail_Session session;
to
Session_Config config;
IMAP_Config config;
to
IMAP_Data imap_data;
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP_Mail_Client.h>
#define WIFI_SSID "my wifi"
#define WIFI_PASSWORD "my-password"
/** For Gmail, the app password will be used for log in
Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in
For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to
https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc
To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password
and AUTHOR_EMAIL with your account email.
*/
/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */
#define SMTP_HOST "<smtp.gmail.com>"
/** The smtp port e.g.
25 or esp_mail_smtp_port_25
465 or esp_mail_smtp_port_465
587 or esp_mail_smtp_port_587
*/
#define SMTP_PORT esp_mail_smtp_port_587 // port 465 is not available for Outlook.com
/* The log in credentials */
#define AUTHOR_EMAIL "my@gmail.com"
// https://myaccount.google.com/apppasswords (https://www.netburner.com/learn/smtp-for-your-embedded-devices/)
//define AUTHOR_PASSWORD "app-password"
#define AUTHOR_PASSWORD "my-password"
/* Recipient email address */
#define RECIPIENT_EMAIL "<my-account@hotmail.com>"
/* Declare the global used SMTPSession object for SMTP transport */
SMTPSession smtp;
/* Callback function to get the Email sending status */
void smtpCallback(SMTP_Status status);
// const char rootCACert[] PROGMEM = "-----BEGIN CERTIFICATE-----\n"
// "-----END CERTIFICATE-----\n";
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();
/* Set the network reconnection option */
MailClient.networkReconnect(true);
// The WiFi credentials are required for Pico W
// due to it does not have reconnect feature.
/** Enable the debug via Serial port
0 for no debugging
1 for basic level debugging
Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h
*/
smtp.debug(1);
/* Set the callback function to get the sending results */
smtp.callback(smtpCallback);
/* Declare the Session_Config for user defined session credentials */
Session_Config config;
/* Set the session config */
config.server.host_name = SMTP_HOST;
config.server.port = SMTP_PORT;
config.login.email = AUTHOR_EMAIL;
config.login.password = AUTHOR_PASSWORD;
/** Assign your host name or you public IPv4 or IPv6 only
as this is the part of EHLO/HELO command to identify the client system
to prevent connection rejection.
If host name or public IP is not available, ignore this or
use generic host "mydomain.net".
Assign any text to this option may cause the connection rejection.
*/
Serial.println("config.login.user_domain = mydomain.net...");
config.login.user_domain = F("mydomain.net");
/*
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
*/
Serial.println ("geting NTP...");
config.time.ntp_server = F("pool.ntp.org,time.nist.gov");
config.time.gmt_offset = 0;
config.time.day_light_offset = 0;
config.time.timezone_env_string = "IST-2";
/* The full message sending logs can now save to file */
/* Since v3.0.4, the sent logs stored in smtp.sendingResult will store only the latest message logs */
// config.sentLogs.filename = "/path/to/log/file";
// config.sentLogs.storage_type = esp_mail_file_storage_type_flash;
/** In ESP32, timezone environment will not keep after wake up boot from sleep.
The local time will equal to GMT time.
To sync or set time with NTP server with the valid local time after wake up boot,
set both gmt and day light offsets to 0 and assign the timezone environment string e.g.
config.time.ntp_server = F("pool.ntp.org,time.nist.gov");
config.time.gmt_offset = 0;
config.time.day_light_offset = 0;
config.time.timezone_env_string = "JST-9"; // for Tokyo
The library will get (sync) the time from NTP server without GMT time offset adjustment
and set the timezone environment variable later.
This timezone environment string will be stored to flash or SD file named "/tze.txt"
which set via config.time.timezone_file.
See the timezone environment string list from
https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv
*/
/* Declare the message class */
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");
message.addRecipient(F("Someone"), RECIPIENT_EMAIL);
String textMsg = "This is simple plain text message";
message.text.content = textMsg;
/** If the message to send is a large string, to reduce the memory used from internal copying while sending,
you can assign string to message.text.blob by cast your string to uint8_t array like this
String myBigString = "..... ......";
message.text.blob.data = (uint8_t *)myBigString.c_str();
message.text.blob.size = myBigString.length();
or assign string to message.text.nonCopyContent, like this
message.text.nonCopyContent = myBigString.c_str();
Only base64 encoding is supported for content transfer encoding in this case.
*/
/** The Plain text message character set e.g.
us-ascii
utf-8
utf-7
The default value is utf-8
*/
message.text.charSet = F("us-ascii");
/** The content transfer encoding e.g.
enc_7bit or "7bit" (not encoded)
enc_qp or "quoted-printable" (encoded)
enc_base64 or "base64" (encoded)
enc_binary or "binary" (not encoded)
enc_8bit or "8bit" (not encoded)
The default value is "7bit"
*/
message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
// If this is a reply message
// message.in_reply_to = "<parent message id>";
// message.references = "<parent references> <parent message id>";
/** The message priority
esp_mail_smtp_priority_high or 1
esp_mail_smtp_priority_normal or 3
esp_mail_smtp_priority_low or 5
The default value is esp_mail_smtp_priority_low
*/
message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low;
// message.response.reply_to = "someone@somemail.com";
// message.response.return_path = "someone@somemail.com";
/** The Delivery Status Notifications e.g.
esp_mail_smtp_notify_never
esp_mail_smtp_notify_success
esp_mail_smtp_notify_failure
esp_mail_smtp_notify_delay
The default value is esp_mail_smtp_notify_never
*/
// 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(F("Message-ID: <abcde.fghij@gmail.com>"));
// For Root CA certificate verification (ESP8266 and ESP32 only)
// config.certificate.cert_data = rootCACert;
// or
// config.certificate.cert_file = "/path/to/der/file";
// config.certificate.cert_file_storage_type = esp_mail_file_storage_type_flash; // esp_mail_file_storage_type_sd
// config.certificate.verify = true;
// The WiFiNINA firmware the Root CA certification can be added via the option in Firmware update tool in Arduino IDE
/* Connect to server with the session config */
// Library will be trying to sync the time with NTP server if time is never sync or set.
// This is 10 seconds blocking process.
// If time synching was timed out, the error "NTP server time synching timed out" will show via debug and callback function.
// You can manually sync time by yourself with NTP library or calling configTime in ESP32 and ESP8266.
// Time can be set manually with provided timestamp to function smtp.setSystemTime.
/* Connect to the server */
if (!smtp.connect(&config))
{
ESP_MAIL_PRINTF("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str());
return;
}
/** Or connect without log in and log in later
if (!smtp.connect(&config, false))
return;
if (!smtp.loginWithPassword(AUTHOR_EMAIL, AUTHOR_PASSWORD))
return;
*/
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, &message))
ESP_MAIL_PRINTF("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str());
// to clear sending result log
// smtp.sendingResult.clear();
}
void loop()
{
}
/* 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)
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", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str());
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();
}
}
Interesting. When I returened to the originial exampleand just modified the required email addresses and password, I git the following debug details on my Serial Monitor:
Connecting to SMTP server...
C: ESP Mail Client v3.1.8
C: wait for NTP server time synching
C: connecting to SMTP server
C: Host > smtp.gmail.com
C: Port > 587
SMTP server connected
C: SMTP server connected, wait for greeting...
< S: 220 smtp.gmail.com ESMTP e13-20020a5d65cd000000b0030789698eebsm3938637wrw.89 - gsmtp
Sending greeting response...
C: send SMTP command, HELO
< S: 250-smtp.gmail.com at your service, [77.138.112.17]
< 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...
C: send command, STARTTLS
< S: 220 2.0.0 Ready to start TLS
Error, SMTP server greeting failed
! E: SMTP server greeting failed
Connection error, Status Code: 220, Error Code: -102, Reason: SMTP server greeting failed
Wrong bees, wrong honey )))
I returned to the original example and just added SSID and password and received exactly the same debug infor. I made some reaserch and got into conclusion that error occurs when the client (my device) in the phase where client and server negotiate a shared encryption key and .
should establish a secure channel for communication
I am attaching below the sketch (just removed SSID details) and afterwards the debug info. no matter if I add the device email details or not. same debug results
/**
* This example showes how to send text Email.
*
* Created by K. Suwatchai (Mobizt)
*
* Email: suwatchai@outlook.com
*
* Github: https://github.com/mobizt/ESP-Mail-Client
*
* Copyright (c) 2023 mobizt
*
*/
/** ////////////////////////////////////////////////
* Struct data names changed from v2.x.x to v3.x.x
* ////////////////////////////////////////////////
*
* "ESP_Mail_Session" changes to "Session_Config"
* "IMAP_Config" changes to "IMAP_Data"
*
* Changes in the examples
*
* ESP_Mail_Session session;
* to
* Session_Config config;
*
* IMAP_Config config;
* to
* IMAP_Data imap_data;
*
*/
#include <Arduino.h>
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#else
// Other Client defined here
// To use custom Client, define ENABLE_CUSTOM_CLIENT in src/ESP_Mail_FS.h.
// See the example Custom_Client.ino for how to use.
#endif
#include <ESP_Mail_Client.h>
#define WIFI_SSID "my-wifi"
#define WIFI_PASSWORD "my-password"
/** For Gmail, the app password will be used for log in
* Check out https://github.com/mobizt/ESP-Mail-Client#gmail-smtp-and-imap-required-app-passwords-to-sign-in
*
* For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to
* https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc
*
* To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password
* and AUTHOR_EMAIL with your account email.
*/
/** The smtp host name e.g. smtp.gmail.com for GMail or smtp.office365.com for Outlook or smtp.mail.yahoo.com */
#define SMTP_HOST "smtp.gmail.com"
/** The smtp port e.g.
* 25 or esp_mail_smtp_port_25
* 465 or esp_mail_smtp_port_465
* 587 or esp_mail_smtp_port_587
*/
#define SMTP_PORT esp_mail_smtp_port_587 // port 465 is not available for Outlook.com
/* The log in credentials */
#define AUTHOR_EMAIL "<email>"
#define AUTHOR_PASSWORD "<password>"
/* Recipient email address */
#define RECIPIENT_EMAIL "<recipient email here>"
/* Declare the global used SMTPSession object for SMTP transport */
SMTPSession smtp;
/* Callback function to get the Email sending status */
void smtpCallback(SMTP_Status status);
// const char rootCACert[] PROGMEM = "-----BEGIN CERTIFICATE-----\n"
// "-----END CERTIFICATE-----\n";
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
WiFiMulti multi;
#endif
void setup()
{
Serial.begin(115200);
#if defined(ARDUINO_ARCH_SAMD)
while (!Serial)
;
Serial.println();
Serial.println("**** Custom built WiFiNINA firmware need to be installed.****\n");
Serial.println("To install firmware, read the instruction here, https://github.com/mobizt/ESP-Mail-Client#install-custom-build-wifinina-firmware");
#endif
Serial.println();
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
multi.addAP(WIFI_SSID, WIFI_PASSWORD);
multi.run();
#else
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
#endif
Serial.print("Connecting to Wi-Fi");
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
unsigned long ms = millis();
#endif
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
if (millis() - ms > 10000)
break;
#endif
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
/* Set the network reconnection option */
MailClient.networkReconnect(true);
// The WiFi credentials are required for Pico W
// due to it does not have reconnect feature.
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
MailClient.clearAP();
MailClient.addAP(WIFI_SSID, WIFI_PASSWORD);
#endif
/** Enable the debug via Serial port
* 0 for no debugging
* 1 for basic level debugging
*
* Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h
*/
smtp.debug(1);
/* Set the callback function to get the sending results */
smtp.callback(smtpCallback);
/* Declare the Session_Config for user defined session credentials */
Session_Config config;
/* Set the session config */
config.server.host_name = SMTP_HOST;
config.server.port = SMTP_PORT;
config.login.email = AUTHOR_EMAIL;
config.login.password = AUTHOR_PASSWORD;
/** Assign your host name or you public IPv4 or IPv6 only
* as this is the part of EHLO/HELO command to identify the client system
* to prevent connection rejection.
* If host name or public IP is not available, ignore this or
* use generic host "mydomain.net".
*
* Assign any text to this option may cause the connection rejection.
*/
config.login.user_domain = F("mydomain.net");
/*
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 = F("pool.ntp.org,time.nist.gov");
config.time.gmt_offset = 3;
config.time.day_light_offset = 0;
/* The full message sending logs can now save to file */
/* Since v3.0.4, the sent logs stored in smtp.sendingResult will store only the latest message logs */
// config.sentLogs.filename = "/path/to/log/file";
// config.sentLogs.storage_type = esp_mail_file_storage_type_flash;
/** In ESP32, timezone environment will not keep after wake up boot from sleep.
* The local time will equal to GMT time.
*
* To sync or set time with NTP server with the valid local time after wake up boot,
* set both gmt and day light offsets to 0 and assign the timezone environment string e.g.
config.time.ntp_server = F("pool.ntp.org,time.nist.gov");
config.time.gmt_offset = 0;
config.time.day_light_offset = 0;
config.time.timezone_env_string = "JST-9"; // for Tokyo
* The library will get (sync) the time from NTP server without GMT time offset adjustment
* and set the timezone environment variable later.
*
* This timezone environment string will be stored to flash or SD file named "/tze.txt"
* which set via config.time.timezone_file.
*
* See the timezone environment string list from
* https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv
*
*/
/* Declare the message class */
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");
message.addRecipient(F("Someone"), RECIPIENT_EMAIL);
String textMsg = "This is simple plain text message";
message.text.content = textMsg;
/** If the message to send is a large string, to reduce the memory used from internal copying while sending,
* you can assign string to message.text.blob by cast your string to uint8_t array like this
*
* String myBigString = "..... ......";
* message.text.blob.data = (uint8_t *)myBigString.c_str();
* message.text.blob.size = myBigString.length();
*
* or assign string to message.text.nonCopyContent, like this
*
* message.text.nonCopyContent = myBigString.c_str();
*
* Only base64 encoding is supported for content transfer encoding in this case.
*/
/** The Plain text message character set e.g.
* us-ascii
* utf-8
* utf-7
* The default value is utf-8
*/
message.text.charSet = F("us-ascii");
/** The content transfer encoding e.g.
* enc_7bit or "7bit" (not encoded)
* enc_qp or "quoted-printable" (encoded)
* enc_base64 or "base64" (encoded)
* enc_binary or "binary" (not encoded)
* enc_8bit or "8bit" (not encoded)
* The default value is "7bit"
*/
message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
// If this is a reply message
// message.in_reply_to = "<parent message id>";
// message.references = "<parent references> <parent message id>";
/** The message priority
* esp_mail_smtp_priority_high or 1
* esp_mail_smtp_priority_normal or 3
* esp_mail_smtp_priority_low or 5
* The default value is esp_mail_smtp_priority_low
*/
message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low;
// message.response.reply_to = "someone@somemail.com";
// message.response.return_path = "someone@somemail.com";
/** The Delivery Status Notifications e.g.
* esp_mail_smtp_notify_never
* esp_mail_smtp_notify_success
* esp_mail_smtp_notify_failure
* esp_mail_smtp_notify_delay
* The default value is esp_mail_smtp_notify_never
*/
// 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(F("Message-ID: <abcde.fghij@gmail.com>"));
// For Root CA certificate verification (ESP8266 and ESP32 only)
// config.certificate.cert_data = rootCACert;
// or
// config.certificate.cert_file = "/path/to/der/file";
// config.certificate.cert_file_storage_type = esp_mail_file_storage_type_flash; // esp_mail_file_storage_type_sd
// config.certificate.verify = true;
// The WiFiNINA firmware the Root CA certification can be added via the option in Firmware update tool in Arduino IDE
/* Connect to server with the session config */
// Library will be trying to sync the time with NTP server if time is never sync or set.
// This is 10 seconds blocking process.
// If time synching was timed out, the error "NTP server time synching timed out" will show via debug and callback function.
// You can manually sync time by yourself with NTP library or calling configTime in ESP32 and ESP8266.
// Time can be set manually with provided timestamp to function smtp.setSystemTime.
/* Connect to the server */
if (!smtp.connect(&config))
{
ESP_MAIL_PRINTF("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str());
return;
}
/** Or connect without log in and log in later
if (!smtp.connect(&config, false))
return;
if (!smtp.loginWithPassword(AUTHOR_EMAIL, AUTHOR_PASSWORD))
return;
*/
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, &message))
ESP_MAIL_PRINTF("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str());
// to clear sending result log
// smtp.sendingResult.clear();
}
void loop()
{
}
/* 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)
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", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str());
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();
}
}
Connecting to SMTP server...
C: ESP Mail Client v3.1.8
C: wait for NTP server time synching
C: connecting to SMTP server
C: Host > smtp.gmail.com
C: Port > 587
SMTP server connected
C: SMTP server connected, wait for greeting...
< S: 220 smtp.gmail.com ESMTP z18-20020a1c4c12000000b003f188f608b9sm14649069wmf.8 - gsmtp
Sending greeting response...
C: send SMTP command, HELO
< S: 250-smtp.gmail.com at your service, [77.138.112.17]
< 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...
C: send command, STARTTLS
< S: 220 2.0.0 Ready to start TLS
Error, SMTP server greeting failed
! E: SMTP server greeting failed
Connection error, Status Code: 220, Error Code: -102, Reason: SMTP server greeting failed
Google processes mail in a secure channel, you need to add and activate certificates
How do I activated certifications? I used the my specific app-password but per my understanding, the code executing didn't arrived to this point.
Continuation of this thread.https://forum.arduino.cc/t/failed-to-add-library/1123470
I use port 465 for gmail, which works.
Is this a string of 16 lowercase characters.
The app password of the account you're sending from.
Leo..
I have already done that. No matter if I add password or not the code stops with the same error message. From the embedd debig ingo you may see that the handshake started successfully (code 220)...
Yes you are right!!! I change the port to 465 and it works for me either.
Thank you so much!!!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.