Need help 8266 SMTP email send program syntax, terminating string

I’m trying to resurrect an Arduino 8266 based email sender program that was working fine in 2023. Since then I changed email provider service and now with the new email, this program fails at step 32 of 33.

The program successfully:

Logs into local wifi,

Logs into email providers server,

Passes authentication,

Provides to and from email addresses,

Appears to send body text of email, and then the server times out at step 32 of 33

I think the problem is with the terminating string that is supposed to convey the end of the text in the email. In the 2023 version the text was terminated with a simple “.” On a new line, it appears that the 2024 version wants a .

Using the 2023 terminating string yields 550 5.7.1 Message Rejected (104) [F3EC52000E/1721829661-832712]

Using the 2024 terminating string appears to try and send the email , however it times out after about 20 seconds trying.

[Line by line working vs. not working comparison]

// Aug 30-2023  tested and working with old mancave email
// July 18-2024 mancave email is now obsolete, will update to new email *** not working with new email
// note base64 encoding available here: https://www.base64encode.org/

// Note 1HZ blink indicates email sent sucessfully, fast blink indicates failed to send email
// Full example (telnet) and explanation can be found in SMTP Testing.docx


#include <ESP8266WiFi.h>
const char* ssid = "H***********";          // Enter the name of your WiFi Network.
const char* password = "*************";     // Enter WiFi Password.

char server[] = "mail.papamail.net";        // The SMTP Server   pre July18-2024 was mail.*****.com
int loopDelay = 100;

WiFiClient espClient;

void setup() {
  pinMode(2, OUTPUT);
  Serial.begin(115200);
  delay(10);
  Serial.println("");
  Serial.println("");
  Serial.print("Connecting To: ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  WiFi.hostname("ESP8266_Sender");

  while (WiFi.status() != WL_CONNECTED) {
       delay(500);
       Serial.print("*");
  }
  Serial.println("");
  Serial.println("WiFi Connected.");        //  2023 and 2024, so far so good
  byte ret = sendEmail();

  delay(1000);

}  // Setup ends

void loop(){
    digitalWrite(2, HIGH);                  // turn the LED on (HIGH is the voltage level)
    delay(loopDelay);                       // wait for a second
    digitalWrite(2, LOW);                   // turn the LED off by making the voltage LOW
    delay(loopDelay);                       // wait for a second
    Serial.println("Looping");
}

byte sendEmail() {
  if (espClient.connect(server, 587) == 1)  {   // 587 works Aug-2023 and 2024,  2024 update tried 465, stops here with 465
       Serial.println(F("connected to port 587"));          // got this far with 587.....
  } else {
       Serial.println(F("connection failed"));
       return 0;
  }
  if (!emailResp()) {
    Serial.println("failed 111");
    return 0;
  }
  Serial.println(F("Sending EHLO"));
  espClient.println("EHLO mail.papamail.net");  // was espClient.println("EHLO mail.*****.com");
  if (!emailResp()) {
      Serial.println("EHLO failed");
       return 0;
  }
  Serial.println(F("Sending auth login"));
  espClient.println("AUTH LOGIN");
  if (!emailResp()) {
       Serial.println("AUTH LOGIN failed");
       return 0;
  }
  Serial.println(F("Sending User info@*****.com"));       // July 18, 2024, so far so good
  espClient.println("***************=");                  // Paste your base64 encoded Username here. Updated to 2024 encoded password, so far so good
  if (!emailResp()) {
       Serial.println("Username failed");
       return 0;
  }
  Serial.println(F("Sending Password"));
  espClient.println("**********=");                       // Paste your base64 encoded Password here, so far so good

  if (!emailResp()) {
      Serial.println(F("Password failed "));
       return 0;
  }

  Serial.println(F("Sending From info@*****.com"));             // 2024 so far so good
  // note re next line, 2023 version did not use carrots, 2024 sender would fail here without <>, adding carrots fixed.
  espClient.println(F("MAIL From:<info@*****.com>"));           // Sender email address,  new version 2024  ok now with carrots. so far so good
  if (!emailResp()) {
      Serial.println(F("MAIL From:<info@*****.com> failed "));
       return 0;
  }

  Serial.println(F("Sending To info@*****.com"));
  // note re next line, 2023 version did not use <>, 2024 sender would fail here without <>, adding <> fixed.
  espClient.println(F("RCPT To:<info@*****.com>"));    // new version with <> 2024, so far so good
  if (!emailResp()) {
       Serial.println(F("RCPT To:<info@*****.com> failed "));
       return 0;
  }

// ***************************  everything appears to work as normal until this point, exactley where is breaks beyond this point is not clear  ****************
  Serial.println(F("Sending DATA 8266 sender message 2024."));
  espClient.println(F("DATA"));                                                       // 2024 not sure???
  espClient.println(F("Subject: 8266 sender message 2024"));                          // 2024 not sure???
  espClient.println(F("8266 sender message 2024"));                                   // 2024 not sure???
  espClient.println(F("\r"));                                                         // 2024 not sure???
  if (!emailResp()) {
       Serial.println(F("Either DATA, Subject or actual message failed "));           // 2024  this line is not executed, so most likely so far so good
       return 0;
  }
  Serial.println(F("Sending email"));

// terminating string 2023 version that did work without <>, no longer works in 2024
//  espClient.println(F(""));                                                               // 2024 this gives 550 5.7.1 Message Rejected (104) [D5B2E20010/1721861964-932527]
//  espClient.println(F("."));                                                              // 2024         -> 500 5.5.2 Error: bad syntax
//  espClient.println(F(""));


// terminating string 2024 version with <>, that appears to work
  espClient.println(F("<>"));                                                               // this version appears to try and send, makes it to here and times out tryimg to send
  espClient.println(F("<.>"));
  espClient.println(F("<>"));

  if (!emailResp()) {
      Serial.println(F("post email failed "));
       return 0;
  }
  Serial.println(F("Sending QUIT"));
  espClient.println(F("QUIT"));
  if (!emailResp())
       return 0;

  espClient.stop();
  Serial.println(F("disconnected"));
  loopDelay = 1000;
  return 1;
}   // SendEmail ends eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee



// Functions start here


byte emailResp() {
  byte responseCode;
  byte readByte;
  int loopCount = 0;

  while (!espClient.available()) {
       delay(1);
       loopCount++;

       if (loopCount > 20000)
       {
       espClient.stop();
       Serial.println(F("\r\nTimeout"));
       return 0;
       }
  }

  responseCode = espClient.peek();
  while (espClient.available()) {
       readByte = espClient.read();
       Serial.write(readByte);
  }

  if (responseCode >= '4') {

       return 0;
  }
  return 1;
}
// nnnnnnnnnnnnnnnnnnnnnnnnnn   ends nnnnnnnnnnnnnn

Do you have a smtp client working on a computer where you could run wireshark to see what’s going on?

Are you sure the mail service provider did not tighten security?

It's possible the mail service provider did tighten security, but If they did I need to figure out a way to comply.

I don't know what a smtp client is but Arduino is running under Win7 and I just installed wireshark on that PC. First time using wireshark. If I enter the IP address of my PC into wireshark (ip.address = 10.x x .x ), I see data to/from my PC.

I know the IP address of my Arduino board is 10.0.0.243, so I tried entering that into wireshark half expecting it to show me something, but I guess it can only snoop the data on the PC it's installed and not the wifi data from the Arduino board?

I don’t use windows
The idea would be to configure a mail client that is using SMTP on your PC and configure it so that it works with the server.

Then you could use wire shark to see what’s going on over the network and mimic that on your arduino.

SMTP on its own is not inherently secure, as it was designed without encryption or authentication mechanisms.

Given the spams and risks associated, providers add layers and make it more secure through the use of additional protocols and methods.

Login and password authentication alone is not secure enough due to vulnerabilities like phishing and credential theft, prompting providers to move towards more secure methods like two-factor authentication and OAuth if sticking to login.

Very often they would be adding a crypted communication layer with TLS like STARTTLS or SMTPS (SMTP over SSL/TLS) .

You should contact your provider to ask for the details.

If your email provider accepts plaintext passwords then you can try to telnet to SMTP port and do it step by step by typing appropriate commands and see what server replies. Then post the response here

an example: How to use Telnet to test SMTP servers | Mailosaur