Page 1 of 1

SMTP Authentication failed ramdomly

Posted: Thu Oct 15, 2020 8:16 pm
by EB Solution
Hello everyone,
I'm facing an issue to send an email using ESP32_Mail_Client librairie with IDE Arduino 1.8.42 from Windows Store
I connect the ESP32 to the WIFI, and it always works.
After that I need to send an email.
Problem is that authentication works ramdomly so the mail isn't always sent.

Board is ESP-WROOM-32 .

Here is the code i use to send the email :

First a set WIFI connexion :

Code: Select all

WiFi.setTxPower(WIFI_POWER_19dBm);
WiFi.begin(ssid, password);   
while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
   delay(200);
  }
then I prepare the email :

Code: Select all

smtpData.setLogin("ssl0.ovh.net", 465, "senderEmail@my.mail", "myPassword");
smtpData.setSender("Sender", "senderEmail@my.mail");
smtpData.setPriority("High");
smtpData.setSubject("mySubject");
smtpData.setMessage("myMessage", true);
smtpData.addRecipient("receiver@my.mail");
smtpData.setSendCallback(sendCallback);
  if (!MailClient.sendMail(smtpData)) {
    Serial.println("Error sending Email, " + MailClient.smtpErrorReason());
  }

  smtpData.empty();
After that I just disconnect WIFI :

  WiFi.disconnect();
  while (WiFi.status() == WL_CONNECTED) {
    Serial.print(".");
    delay(200);
  }
Here is the log when It success :
14:14:05.372 -> Connecting to SMTP server...
--
14:14:05.372 -> [DEBUG] - INFO: connecting to SMTP server...
14:14:05.372 -> [DEBUG] - ssl0.ovh.net
14:14:05.372 -> [DEBUG] - 465
14:14:05.372 -> [DEBUG] - INFO: cleaning SSL connection
14:14:05.372 -> [DEBUG] - INFO: starting socket
14:14:05.372 -> [DEBUG] - INFO: connecting to Server...
14:14:05.416 -> [DEBUG] - INFO: server connected
14:14:05.416 -> [DEBUG] - INFO: seeding the random number generator
14:14:05.416 -> [DEBUG] - INFO: setting up the SSL/TLS structure...
14:14:05.464 -> [DEBUG] - INFO: setting hostname for TLS session...
14:14:05.464 -> [DEBUG] - INFO: performing the SSL/TLS handshake...
14:14:10.160 -> [DEBUG] - INFO: verifying peer X.509 certificate...
14:14:10.160 -> [DEBUG] - INFO: certificate verified
14:14:10.160 -> [DEBUG] - INFO: smtp server connected
14:14:10.160 -> Identification...
14:14:10.160 -> [DEBUG] - INFO: send smtp HELO command
14:14:10.160 -> [DEBUG] - 220 GARM-106R006 Thursday, October 15, 2020
14:14:10.160 ->
14:14:10.204 -> [DEBUG] - 250-OVH SMTP PROXY Hello
14:14:10.204 ->
14:14:10.204 -> [DEBUG] - 250-SIZE 104857600
14:14:10.204 ->
14:14:10.204 -> [DEBUG] - 250-ENHANCEDSTATUSCODES
14:14:10.204 ->
14:14:10.204 -> [DEBUG] - 250-AUTH LOGIN PLAIN
14:14:10.204 ->
14:14:10.204 -> [DEBUG] - 250-AUTH=LOGIN PLAIN
14:14:10.204 ->
14:14:10.204 -> [DEBUG] - 250 8BITMIME
14:14:10.248 ->
14:14:10.248 -> [DEBUG] - 530 5.7.1 Client was not authenticated
14:14:10.248 ->
14:14:10.248 -> Authentication...
14:14:10.248 -> [DEBUG] - INFO: send smtp AUTH LOGIN command
14:14:10.296 -> [DEBUG] - 334 VXNlcm5hbWU6
14:14:10.296 ->
14:14:10.296 -> Sign in...
14:14:10.296 -> [DEBUG] - INFO: log in with username and password
14:14:10.825 -> [DEBUG] - 334 UGFzc3dvcmQ6
14:14:10.825 ->
14:14:11.353 -> [DEBUG] - 235 2.7.0 Authentication successful
14:14:11.353 ->
14:14:11.353 -> Sending Email header...
14:14:11.353 -> [DEBUG] - INFO: send email header
14:14:11.445 -> [DEBUG] - 250 2.1.0 Ok
14:14:11.445 ->
14:14:11.577 -> [DEBUG] - 250 2.1.5 Ok
14:14:11.577 ->
14:14:11.577 -> Sending Email body...
14:14:11.577 -> [DEBUG] - INFO: send email body
14:14:11.921 -> [DEBUG] - 354 End data with <CR><LF>.<CR><LF>
14:14:11.921 ->
14:14:11.921 -> [DEBUG] - INFO: finalize...
14:14:11.965 -> Finalize...
14:14:12.009 -> [DEBUG] - 250 2.0.0 Ok: queued as 51EA91737D554
14:14:12.009 ->
14:14:12.009 -> Finished
14:14:12.009 -> Email sent successfully
14:14:12.009 -> ----------------
14:14:12.009 -> [DEBUG] - INFO: email sent successfully
14:14:12.009 -> [DEBUG] - INFO: cleaning SSL connection
And when it fail to authenticate (order of the logs messages is not always the same when it fail) :
14:20:23.394 -> Connecting to SMTP server...
--
14:20:23.394 -> [DEBUG] - INFO: connecting to SMTP server...
14:20:23.394 -> [DEBUG] - ssl0.ovh.net
14:20:23.394 -> [DEBUG] - 465
14:20:23.394 -> [DEBUG] - INFO: cleaning SSL connection
14:20:23.394 -> [DEBUG] - INFO: starting socket
14:20:23.394 -> [DEBUG] - INFO: connecting to Server...
14:20:23.629 -> [DEBUG] - INFO: server connected
14:20:23.629 -> [DEBUG] - INFO: seeding the random number generator
14:20:23.676 -> [DEBUG] - INFO: setting up the SSL/TLS structure...
14:20:23.676 -> [DEBUG] - INFO: setting hostname for TLS session...
14:20:23.676 -> [DEBUG] - INFO: performing the SSL/TLS handshake...
14:20:26.251 -> [DEBUG] - INFO: verifying peer X.509 certificate...
14:20:26.251 -> [DEBUG] - INFO: certificate verified
14:20:26.251 -> [DEBUG] - INFO: smtp server connected
14:20:26.251 -> Identification...
14:20:26.251 -> [DEBUG] - INFO: send smtp HELO command
14:20:26.251 -> [DEBUG] - 220 GARM-100R003 Thursday, October 15, 2020
14:20:26.251 ->
14:20:26.532 -> [DEBUG] - 250-OVH SMTP PROXY Hello
14:20:26.532 ->
14:20:26.532 -> [DEBUG] - 250-SIZE 104857600
14:20:26.532 ->
14:20:26.532 -> [DEBUG] - 250-ENHANCEDSTATUSCODES
14:20:26.532 ->
14:20:26.532 -> Authentication...
14:20:26.532 -> [DEBUG] - INFO: send smtp AUTH LOGIN command
14:20:26.579 -> [DEBUG] - 250-AUTH LOGIN PLAIN
14:20:26.579 ->
14:20:26.579 -> [DEBUG] - 250-AUTH=LOGIN PLAIN
14:20:26.579 ->
14:20:26.579 -> [DEBUG] - 250 8BITMIME
14:20:26.579 ->
14:20:26.579 -> [DEBUG] - 530 5.7.1 Client was not authenticated
14:20:26.579 ->
14:20:26.579 -> Error, authentication failed
14:20:26.579 -> [DEBUG] - ERROR: authentication failed
14:20:26.626 -> [DEBUG] - INFO: cleaning SSL connection
14:20:26.626 -> Error sending Email, authentication failed
Any Idea how I can solve this random behaviour?

Re: SMTP Authentication failed ramdomly

Posted: Fri Oct 16, 2020 7:12 am
by Spile2
I use the following as my starting point and have never had an authentication problem. Perhaps try the script “as is”, set the credentials and start from there.
https://www.survivingwithandroid.com/se ... tp-server/

Re: SMTP Authentication failed ramdomly

Posted: Thu Feb 02, 2023 1:24 pm
by wilkxt
Hi
Do you resolve problem with autentication?