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