I am developing a sketch that uses an Uno and an ESP8266 to send email via smtp2go. However "HELO" responds with "ERROR". What might be the source of the problem?
To explore this, I created another sketch that simply sends commands to the ESP8266, and displays the results. The wifi connection seems fine, as does the SMTP Server connect to mail.smtp2go.com. However, the next command issued "HELO 10.1.0.35" provides a response of "ERROR".
The ESP8266 is mounted on an ESP-01 board, and set @ 9600 baud. have tested with different chip sets. I have also tried using Gmail [smtp.gmail.com,465 ], but results are the same.
[I know that an ESP8266 can be used stand-alone. However the final sketch requires 13 data pins.]
Output from sketch:
"ESP8266_ATcmdtest", compiled on: Jun 8 2017 at 17:58:18
Running on: Arduino UNO: ATmega328P
__________[ Disable echo (Echo sends back received command before response) ]__________
__________[ ATE0 ]__________
Response buffer:
OK
__________[ Delete server ]__________
__________[ AT+CIPSERVER=0 ]__________
Response buffer:
no change
OK
__________[ Restart the module ]__________
__________[ AT+RST ]__________
Response buffer:
OK
0,CLOSED
WIFI DISCONNECT
bB׆QR⸮⸮⸮ȤRN⸮ɥRL⸮H⸮⸮N⸮⸮d#@⸮⸮
WIFI CONNECTED
__________[ Check Firmware type [Responds with: AT version:1.2.0.0(Jul 1 2016 20:04:45) ]__________
__________[ AT+GMR ]__________
Response buffer:
AT+GMR
AT version:1.2.0.0(Jul 1 2016 20:04:45)
SDK version:WIFI GOT IP
__________[ Lists available APs ]__________
__________[ AT+CWLAP ]__________
Response buffer:
AT+CWLAP
+CWLAP:(0,"KCTcircuit2",-47,"08:bd:43:ff:6a:0c",1,21,0)
+CWLAP:(3,"49KHC",-88,"70:f1:96:66:29:ef",1,11,0)
+CWLAP:(3,"KCTstudy",-49,"04:a1:51:bf:6b:30",5,-11,0)
+CWLAP:(3,"Linksys05761",-75,"b4:75:0
e:64:54:b1",11,21,0)
+CWLAP:(3,"Pccd_main",-91,"14:91:82:83:f8
__________[ Get local IP address, e.g., 192.168.4.1 ]__________
__________[ AT+CIFSR ]__________
Response buffer:
AT+CIFSR
+CIFSR:STAIP,"10.0.0.4"
+CIFSR:STAMAC,"5c:cf:7f:34:
__________[ Set Station mode ]__________
__________[ AT+CWMODE=1 ]__________
Response buffer:
AT+CWMODE=1
OK
__________[ Set current multiplex mode ]__________
__________[ AT+CIPMUX=1 ]__________
Response buffer:
AT+CIPMUX=1
OK
__________[ Connect to AP ]__________
__________[ AT+CWJAP="KCTstudy","[pw redacted]" ]__________
Response buffer:
AT+CWJAP="KCTstudy","[pw redacted]"
WIFI DISCONNECT
WIFI CONNECTED
__________[ Prints the SSID of Access Point ESP8266 is connected to. ]__________
__________[ AT+CWJAP? ]__________
Response buffer:
AT+CWJAP?
busy p...
WIFI GOT IP
OK
__________[ Get IP address of ESP8266 station, e.g., 10.0.0.4 ]__________
__________[ AT+CIPSTA? ]__________
Response buffer:
AT+CIPSTA?
+CIPSTA:ip:"10.0.0.4"
+CIPSTA:gateway:"10.0.0.1"
__________[ SMTPServer connect ]__________
__________[ AT+CIPSTART=0,"TCP","mail.smtp2go.com",2525 ]__________
Response buffer:
AT+CIPSTART=0,"TCP","mail.smtp2go.com",2525
0,CONNECT
OK
+IPD,0,70:220 mail.smtp2go.com ESMTP Exim 4.87 2017年6月09日 00:59:07 +0000
__________[ Get information about connection ]__________
Response format is:
STATUS:stat [ 2: Got IP, 3: Connected, 4: Disconnected]
+CIPSTATUS:id,type,addr,port,tetype [type: TCP, addr: IP address]
OK
__________[ AT+CIPSTATUS ]__________
Response buffer:
AT+CIPSTATUS
STATUS:3
+CIPSTATUS:0,"TCP","173.255.233.87",25
__________[ HELO ]__________
__________[ HELO 10.0.0.8 ]__________
Response buffer:
HELO 10.0.0.4
ERROR
Sketch code
#include <SoftwareSerial.h>
// _______________________________
#define sendit(x) ( { \
Serial.print(F("__________[ ")); \
Serial.print(x); \
Serial.println(F(" ]__________")); \
esp8266.write(x); \
esp8266.write("\r\n"); \
delay(300); \
Serial.println(F("Response buffer: ")); \
for (int i=0; i <= 99; i++) { \
memset(buffer, 0, sizeof(buffer)); \
delay(10); \
bcount = esp8266.readBytes(buffer, sizeof(buffer)); \
if (bcount == 0) i = 100; \
else { \
if (bcount > 1) Serial.println(buffer); \
delay(300); \
} \
} \
} )
// _______________________________
#define desc(x) ( { \
Serial.println(); \
Serial.print(F("__________[ ")); \
Serial.print(F(x)); \
Serial.println(F(" ]__________")); \
} )
// _______________________________
SoftwareSerial esp8266(11, 12); // RX, TX
char buffer[200];
String SerialReadBuffer = "";
char SerialByteIn; // Temporary variable
boolean SerialEnd = false;
int bcount;
// _______________________________
void setup()
{
Initialise();
}
// _______________________________
void loop()
{
}
// ____________________________________________________________________________________________________
void Initialise()
{
SerialReadBuffer.reserve(64);
esp8266.begin(9600);
// esp8266.begin(115200);
Serial.begin(9600);
CommandList2();
}
// ____________________________________________________________________________________________________
void CommandList2()
{
desc("Disable echo (Echo sends back received command before response)");
sendit("ATE0");
desc("Delete server");
sendit("AT+CIPSERVER=0");
desc("Restart the module");
sendit("AT+RST");
desc("Check Firmware type [Responds with: AT version:1.2.0.0(Jul 1 2016 20:04:45)");
sendit("AT+GMR");
desc("Lists available APs");
sendit("AT+CWLAP");
desc("Get local IP address, e.g., 192.168.4.1");
sendit("AT+CIFSR");
desc("Set Station mode");
sendit("AT+CWMODE=1");
desc("Set current multiplex mode");
sendit("AT+CIPMUX=1");
desc("Connect to AP");
sendit("AT+CWJAP=\"KCTstudy\",\"[pw redacted]\"");
desc("Prints the SSID of Access Point ESP8266 is connected to.");
sendit("AT+CWJAP?");
desc("Get IP address of ESP8266 station, e.g., 10.0.0.4");
sendit("AT+CIPSTA?");
desc("SMTPServer connect");
sendit("AT+CIPSTART=0,\"TCP\",\"mail.smtp2go.com\",25");
desc("Get information about connection");
Serial.println(F("Response format is: "));
Serial.println(F("STATUS:stat [ 2: Got IP, 3: Connected, 4: Disconnected]"));
Serial.println(F("+CIPSTATUS:id,type,addr,port,tetype [type: TCP, addr: IP address]"));
Serial.println(F("OK"));
sendit("AT+CIPSTATUS");
//
// Problems start here
//
desc("HELO");
sendit("HELO 10.0.0.4");
Serial.println(F("__________________"));
}
-
1in my (limited) experience, anything beyond pushing and fetching http transactions is flaky and difficult on the AT firmware. You can run a nice custom sketch on the ESP and still use serial to talk to the ardunio, using your own commands instead of the AT ones. The debugging differences are extreme; total flexibility and intermediate logging vs a "black box" with cryptic returns. that also lets you use the pins on the ESP if needed, store 3mb of data locally, etc etc...dandavis– dandavis2017年06月09日 09:26:54 +00:00Commented Jun 9, 2017 at 9:26
-
Most commercial SMTP servers will not accept email from machines not DNS registered. This is to avoid receiving/distributed spam from bot infected PC. I doubt they will accept mail from a 10.x.x.x IP address, because they are not routable. If you are going thru a NAT router, your Internet address will be other. Are you using a local, private SMTP server that you can control?user31481– user314812017年08月08日 11:46:16 +00:00Commented Aug 8, 2017 at 11:46
-
@Look Alterno, I am not very savvy on this subject, but no NAT router or private SMTP server. I have this problem only when using with the ESP8266. I have 3 other Arduino systems using Ethernet shields instead and accessing the same network. These work fine for sending the same kind of Email. For the ESP8266 system, there is simply no Ethernet cable connect available. I have still not sorted this out yet.KC Tucker– KC Tucker2017年08月08日 18:37:28 +00:00Commented Aug 8, 2017 at 18:37
-
I think @majenko has the right answer already. My comment is for others thinking about sending mail. As you are using a comercial paid service (smtp2go.com) that expressly allow that, my comment doesn't applied to you. You get it right.user31481– user314812017年08月08日 18:55:57 +00:00Commented Aug 8, 2017 at 18:55
2 Answers 2
You're sending the word "HELO" to the ESP8266 and the ESP8266 is, quite rightly, saying "What?!?! I don't know the command HELO!"
You have opened a connection in multiple connection mode with ID 0. You then have to send data through that connection. For instance:
AT+CIPSTART=0,"TCP\","mail.smtp2go.com",2525
OK
AT+CIPSEND=0,15
> HELO 10.0.0.4<CR><LF>
SEND OK
Using a protocol like SMTP in this mode is not easy. Better would be to use "unvarnished" mode:
AT+CIPSTART="TCP","mail.smtp2go.com",2525
OK
Linked
AT+CIPMODE=1
OK
AT+CIPSEND
> HELO 10.0.0.4<CR><LF>
250 mail.smtp2go.com Hello 10.0.0.4 [23.114.28.226]
MAIL FROM: "Foo Bar" <[email protected]>
250 OK
... etc ...
QUIT
221 mail.smtp2go.com closing connection
Note that just sending commands and blindly printing the responses isn't really the best way to go about it. You should be actively interpreting the responses that you get back and making decisions based upon them. Especially when you're in SEND mode. The SMTP protocol is two-way. You need to know what the responses are saying and what that means for your SMTP session.
Before sending "HELO 10.0.0.4" ... you should send a CIPsend command with the length of your sentence + 2
Here is the right command sequence:
AT+CIPSEND=4,15
HELO 10.0.0.4
Best regards