SMTP / telnet command help

hey all i know this has been talked about 1000 times, i have found 1000 posts… and i am darn close to makeing this work.

Hardware: Arduino uno back-packed with a wifly shield.

The following is the code that i am using, i am connecting to Comcast to send and email to myself. I know how to make it work in telnet and i have been able to manually complete the email on the uno, but now i am switching over to using a command to send the full email. The problem is occurring when i send the helo to Comcast, i am getting back an error 500 command unrecognized.

the basic code should work as if so:

i input the word “send” into serial log process begins
i first issue exit to make sure i am out of command mode on wifly board
second i enter command mode
i open connection to Comcast
i send helo
i close connection
after i close i reset my sting to blank.

right now i have the open and close working just fine its just the helo i am struggling with, where am i going wrong? I am leaning towards something in the formatting, helo is long multiple chars could be possible causing the problem where as quit is short? any ideas?

Power on testsend
Attepting to concect
CMD
opening port
open smtp.comcast.net 587

Connect to 76.96.40.155:587
<4.41> OPEN220 omta19.emeryville.ca.mail.comcast.net comcast ESMTP server ready
sending helo
500 5.5.1 command unrecognized
closing
221 2.0.0 omta19.emeryville.ca.mail.comcast.net comcast closing connection
CLOS

          Serial.println("sending helo");
          SpiSerial.println("helo smtp.comcast.net");
          delay(10000);
          incoming();
          
  
          Serial.println("closing");
          SpiSerial.println("quit");
          delay(10000);
          incoming();
#include "WiFly.h" // We use this for the preinstantiated SpiSerial object.

void incoming(){
  
    while(SpiSerial.available() > 0) {
         Serial.write(SpiSerial.read());
         delay(5);
    }
    
    delay(500);
}

void outgoing(){
  
  if(Serial.available()) { // Outgoing data
       SpiSerial.write(Serial.read());
   
   }
}

void email(){
  
String readString;
int incomingByte;  
  
  
      while (Serial.available()) {
      delay(10);
      if (Serial.available() > 0) {
          char c = Serial.read(); // Gets one byte from serial buffer
          readString += c; // Makes the string readString
      }
    }

    if (readString.length() > 0) {
        Serial.println( readString); // See what was received
        
        if (readString == "send") {
          
          Serial.println("Attepting to concect");
          incoming();
          delay(250);
           SpiSerial.println("exit\r");
           delay(500);
           
           incoming();
          
          SpiSerial.print("$$");
          delay(300);
          incoming();
          
          Serial.println("opening port");
          SpiSerial.print("open smtp.comcast.net 587\r");
          delay(10000);
          incoming();
          
          Serial.println("sending helo");
          SpiSerial.println("helo smtp.comcast.net");
          delay(10000);
          incoming();
          
  
          Serial.println("closing");
          SpiSerial.println("quit");
          delay(10000);
          incoming();
          
        }
        
        readString = "";

    }
  
  
  
  
 
}


void setup() {

  Serial.begin(9600);
  
  SpiSerial.begin();
  
  Serial.write("Power on test");
    
    
}


void loop() {
  
  email();
  //incoming();
  //outgoing();
  
}
}

ok soo i got it working sort of by changeing my code to the following, can someone explain why its working but i am still getting an error? something must be getting left over from my open command but i am not sure what.

          Serial.println("opening port");
          SpiSerial.print("open smtp.comcast.net 587\r");
          delay(10000);
          incoming();
          
          Serial.println("sending helo");
          SpiSerial.println("\r");
          SpiSerial.println("HELO smtp.comcast.net");
          delay(10000);
          incoming();
          
  
          Serial.println("closing");
          SpiSerial.println("quit");
          delay(10000);
          incoming();

Power on testsend
Attepting to concect
CMD
opening port
open smtp.comcast.net 587

Connect to 76.96.40.155:587
<4.41> OPEN220 omta09.emeryville.ca.mail.comcast.net comcast ESMTP server ready
sending helo
500 5.5.1 command unrecognized
250 omta09.emeryville.ca.mail.comcast.net hello [71.231.89.89], pleased to meet you
closing
221 2.0.0 omta09.emeryville.ca.mail.comcast.net comcast closing connection
CLOS

sending helo
500 5.5.1 command unrecognized

Try a spelling checker!

Mark

..... ye... not so much. the command is actually supposed to be helo. its is the RFC 821 standard for email smtp to say hello. Thanks any who...

          SpiSerial.println("\r");
          SpiSerial.println("HELO smtp.comcast.net");

'\r' is a line ending, println also sends a line ending '\n'? sending both may be the "bad char".

Mark

Even if you get past that, chances are Comcast will not let you send email on port 587 without TLS, and no Arduino library I am aware of supports TLS encryption. The Comcast server should send a "STARTTLS" message next, and you can't do that. :frowning:

To login to the server is actualy quite easy below is the sequence i am using over telnet. unless there is something i am missing, would telnet support tls without having to do any thing special? i send each string in succession and it works great over telnet, the farthest i went with the arduino manually was to send the helo and then authenticate both manually were successful, though i never actually sent an email over the arduino but i have several times over telnet. i just got to that point and figured it would work. now you have me thinking.

telnet smtp.comcast.net 587

helo smtp.comcast.net

AUTH Login

Login 64 bit encrypted

Password 64bit encrypted

mail from:<blank@comcast.net>

RCPT To:<blank@comcast.net>

DATA

Subject: test message sent from arduino

Hello World,
This is a test message sent from a manual telnet session.

Yours truly,
SMTP administrator

 
 .

quit

holmes4:

          SpiSerial.println("\r");

SpiSerial.println(“HELO smtp.comcast.net”);




'\r' is a line ending, println also sends a line ending '\n'? sending both may be the "bad char".

Mark

i did drop the r but then i dont recieve a helo back

Power on testsend
CMD
open smtp.comcast.net 587

Connect to 76.96.40.155:587
<4.41>
OPEN220 omta19.emeryville.ca.mail.comcast.net comcast ESMTP server ready
500 5.5.1 command unrecognized
221 2.0.0 omta19.emeryville.ca.mail.comcast.net comcast closing connection
CLOS

If i put the “/r” or “” back in with print i get the same thing, but if i put that line back in it sends me a hello back

Power on testsend
CMD
open smtp.comcast.net 587

Connect to 76.96.40.155:587
<4.41>
OPEN220 omta13.emeryville.ca.mail.comcast.net comcast ESMTP server ready
500 5.5.1 command unrecognized
250 omta13.emeryville.ca.mail.comcast.net hello [“BLANK”], pleased to meet you
221 2.0.0 omta13.emeryville.ca.mail.comcast.net comcast closing connection
CLOS

All of this tells me that there is something being left over or accdentily sent but for the life of me i can’t figure out what it is.

is there a way to send a string with no newline or return ends?

Well i am getting closer… that one error is still buggin me…

Power on testsend
CMD
open smtp.comcast.net 587

Connect to 76.96.40.155:587
<4.41> OPEN220 omta24.emeryville.ca.mail.comcast.net comcast ESMTP server ready
500 5.5.1 command unrecognized
250 omta24.emeryville.ca.mail.comcast.net hello [BLANK], pleased to meet you
334 VXNlcm5hbWU6
334 UGFzc3dvcmQ6
235 2.7.0 … Authentication succeeded
221 2.0.0 omta24.emeryville.ca.mail.comcast.net comcast closing connection
CLOS

What are you sending as a hello after this?

220 omta24.emeryville.ca.mail.comcast.net comcast ESMTP server ready

I use this with my email code.

  // change 1.2.3.4 to your public ip
  client.println(F("helo 1.2.3.4"));

You can see my ethernet code here:
http://playground.arduino.cc/Code/Email
It doesn’t use any authentication because it sends email like one email server sends to another email server, but it may help you with the protocol.

SurferTim you had me scared but it seems all is working fine for now… if only i could figure out what was causing that 500 error. I know i read something that if you are on one of the ISP’s IP addresses that they are more open to communicaion. So now time to build a bit more code and clean up what i have. Then take it on the road for testing.

Power on testsend
CMD
open smtp.comcast.net 587

Connect to 76.96.40.155:587
<4.41> OPEN220 omta01.emeryville.ca.mail.comcast.net comcast ESMTP server ready
500 5.5.1 command unrecognized
250 omta01.emeryville.ca.mail.comcast.net hello [BLANK], pleased to meet you
334 VXNlcm5hbWU6
334 UGFzc3dvcmQ6
235 2.7.0 … Authentication succeeded
250 2.1.0 BLANK@comcast.net sender ok
250 2.1.5 BLANK@comcast.net recipient ok
354 enter mail, end with “.” on a line by itself
250 2.0.0 mail accepted for delivery
221 2.0.0 omta01.emeryville.ca.mail.comcast.net comcast closing connection
CLOS

What ever the server is not likeing is bewteen the open command and the helo.

char start[] = "open smtp.comcast.net 587";
char helo[] = "HELO smtp.comcast.net";
clearLCD();
          lcdPosition(0,0);
          LCD.println("opening port");
          SpiSerial.print(start);
          SpiSerial.print("\r");
          delay(400);
          incoming();
          
          clearLCD();
          lcdPosition(0,0);
          LCD.println("sending helo");
          SpiSerial.print("\r\n");
          SpiSerial.println(helo);
          delay(400);
          incoming();

I am surprised Comcast doesn't require TLS on port 587, but it is not required.

I think it is the cr/lf send before the helo send.

          LCD.println("sending helo");

          // I think it is this:
          SpiSerial.print("\r\n");

          SpiSerial.println(helo);

I was shocked too but seems to be working. If i drop that line it it messes everything else up, at this point it must be some junk data the board is spitting out and by keeping that line i am in short clearing it and starting fresh.... i guess for now its working the way i want it to, i just hate having the error code pop up but why fret if it is working right?

Hi - first post here

So this has been very helpful but Im having one issue and maybe some one can help me under stand before I go any further?

To verify all my cmds and logins were good I opened up a telnet session in windows and followed Tallguys cmd lines and it looks as if I sent an email… however I dont see it come thru in my gmail account??? but it said “accepted for delivery” so whats up? blocked?

thanks in advance.

telnet smtp.comcast.net 587
220 resomta-po-07v.sys.comcast.net comcast ESMTP server ready
helo smtp.comcast.net
250 resomta-po-07v.sys.comcast.net hello [11.111.111.111], pleased to meet you
AUTH Login
334 VXNlcm5hbWU6 (user64b)
334 UGFzc3dvcmQ6 (pw64b)

235 2.7.0 … Authentication succeeded

mail from:fmlast@comcast.net
250 2.1.0 fmlast@comcast.net sender ok
RCPT To:fmlast@gmail.com
250 2.1.5 fmlast@gmail.com recipient ok
DATA
354 enter mail, end with “.” on a line by itself

To: first fmlast@gmail.net
From: first fmlast@comcast.net
Subject: Arduino email test\r\n
This is from my Arduino!
.
250 2.0.0 xeMR1o00l2Grcle01eN0RE mail accepted for delivery
quit
221 2.0.0 resomta-po-07v.sys.comcast.net comcast closing connection

That looks as if it took your email. Check your spam folder.

Man your fast!

looks like the emails were accepted but bounced by Comcast since I revived two “Delivery status notification” about 10mins later: “Delivery to the following recipients was aborted after 0 second(s):” fmlast@gmail.com

So i tried changing the To: and From: both to the fmlast@comcast.net adders and bingo! email sent instantly… however it looks totally like SPAM. Its says its from “Unknown” and (NOT GOOD)

So i think i messed up the cmd line order? or missed one?
mail from…
RCPT To…
DATA…
To: …
From: …
Subject …
.

my email subject is blank and the body looks like this:
From: NAME fmlast@comcast.net
Subject: Arduino email test\r\n
This is from my Arduino!

thanks

AG

I have email code for the Arduino, but is designed for port 25. It has all but the AUTH part in the correct order from what I have tested. Maybe it will give you an idea about the send that you are missing or out of order.
http://playground.arduino.cc/Code/Email

ok cool, yup that’s the code/thread that got me here. Nice work.

I figured out what was going on. Its kinda weird and was due to or spacing but probably bc im on a cmd line telnet . Here is the solution in red

…after the DATA cmd, press enter.
To: NAME fmlast@comcast.net (press enter)
From: NAME fmlast@comcast.net (press enter)
Subject: Arduino email test (press enter TWO TIMES)

now type email body (press enter TWO TIMES)

. (press enter)

then you get a proper email to your gmail account!!!

thanks for all your help, now its onto making the sketch knowing the smtp is good.

AG