SMTP Authentication failed ramdomly

EB Solution
Posts: 2
Joined: Thu Oct 15, 2020 6:34 pm

SMTP Authentication failed ramdomly

Postby EB Solution » Thu Oct 15, 2020 8:16 pm

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?

Spile2
Posts: 23
Joined: Tue Sep 22, 2020 8:39 pm

Re: SMTP Authentication failed ramdomly

Postby Spile2 » Fri Oct 16, 2020 7:12 am

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/

wilkxt
Posts: 15
Joined: Sun Mar 06, 2016 7:46 pm

Re: SMTP Authentication failed ramdomly

Postby wilkxt » Thu Feb 02, 2023 1:24 pm

Hi
Do you resolve problem with autentication?
best regards, Tom

Who is online

Users browsing this forum: No registered users and 42 guests