Client.read() only works once.

I am writing a simple SMTP mail client. I can NOT get past HELO.

It recieves the “220 blah blah blah”, sends “HELO friend” and awaits a response, none comes. client.available() goes to zero and stays there.

Over telnet there is an immediate response.

bool Gsender_Send() {
  String code;
  char *messageC;
  Serial.print("GSender_send");
  String mailFrom = "MAIL FROM: <" + smtpFrom + '>';
  char *mailFromC;
  mailFrom.toCharArray(mailFromC, 100);
  Serial.print("mail from");
  String rcpt = "RCPT TO: <" + smtpTo + '>';
  char *rcptC;
  rcpt.toCharArray(rcptC, 100);
  Serial.print("to");
  String message = "From: <" + smtpFrom + ">\nTo: <" + smtpTo + ">\nSubject:\n" + subject + "Mime-Version: 1.0\nContent-Type: text/html; charset=\"UTF-8\"\nContent-Transfer-Encoding: 7bit\n\n" + body + "\n.\n";
  message.toCharArray(messageC, 1000);
  Serial.print("from");

  char* csmtp_pass;
  smtp_pass.toCharArray(csmtp_pass, 16);
  Serial.print("tochararary");

  int smtpStep[11] = {   1,      2,              3,            4,                       5,                     6,                                    7,                               8,           9,      10 };
  Serial.print("smtpStep array");
  //char *s64login = encode64(csmtpUserID);
  Serial.println("uid encode");
  //char *s64pass = encode64(csmtp_pass);
  Serial.println("pass encode");
  char *smtpCmd[11] = { "HELO Friend",     "AUTH LOGIN",     s64login,                    s64pass,                  mailFromC,                          rcptC,     "DATA",   messageC,  "QUIT" };
  Serial.println("smtp command array");
  char *smtpCode[11] = { "220",     "250",             "334",         "334",                       "235",                   "250",                                 "250",         "354",       "250",         "0" };
  Serial.println("smtp codesnip dec");
  char *smtpCodeSnip;

  //Test
  long stmpTimeOut = 15000;
  Serial.print("IPaddress");
  IPAddress smtp_server(67, 195, 228, 95);
  smtp_port = 587;

  DEBUG_AM("Connecting to :");
  DEBUG_AM(smtp_server);
  DEBUG_AM(smtp_port);
  Serial.println("pre connect");
  client.connect(smtp_server, smtp_port);
  Serial.println("post connect");
  String readChars;
  char readCharsC[100];
  long doMS = millis();
  do { // CONNECT
    if (millis() - doMS > stmpTimeOut) {
      Serial.print("Timed out waiting for connection.");
    }
  }
  while (!client.connected());

  for (int i = 0; i < 11; i++) {
    delay(100);
    doMS = millis();

    int cI = 0;
    int bytes = client.available();
    if (bytes == 0) {
      do {
        delay(100);
        Serial.print(".");
      }
      while (client.available() == 0);
    }

    Serial.printf("Bytes in read buffer: %d", bytes);
    memset(readCharsC, 0, 100);
    do { //Read
      char c = client.read();
      readCharsC[cI] = c;
      if (cI == 2) code = String(readCharsC);
      cI++;
      bytes--;
    }
    while (bytes > 0);
    client.flush();
    Serial.printf("Readchars: %s, code %s", readCharsC, code.c_str());
    //Interpret
    if (code == smtpCode[i]) {
      Serial.println("Got anticipated response");
    }
    else {
      Serial.printf("Got response not anticpated, %s. Aborting.", code.c_str());
      client.print("QUIT");
      return false;
    }
    //Reply
    Serial.printf("Sending %s", smtpCmd[i]);
    client.print(smtpCmd[i]);
  }
  client.println("QUIT");
  return true;
}

HERE is the serial transcript. Note I have wifi debug on.

GSender_sendmail fromtofromtocharararysmtpStep arrayuid encode
pass encode
smtp command array
smtp codesnip dec
IPaddress*ALERTME: Connecting to :
*ALERTME: 67.195.228.95
*ALERTME: 587
pre connect
post connect
1234.67Bytes in read buffer: [37]89Readchars: 220 smtp.mail.yahoo.com ESMTP ready
, code 220Got anticipated response
Sending HELO Friend1234.......................................................................................pm open,type:2 0

All of your char pointers are not yet allocated. So you are writing to memory you don't own. So weird stuffs happen.

would I define my char pointers then as blah = malloc(32);? I heard using malloc wasn't a good idea.

mattlogue:
would I define my char pointers then as blah = malloc(32);? I heard using malloc wasn't a good idea.

Is it a bad idea and you don't need to. You can declare static char with fixed size either globally or locally.

I really don't think my char definitions are causing it not to read a second time from client... any idea why it gets "Bytes in read buffer: [70]89Readchars: 220 mail.smtp2go.com ESMTP Exim 4.91 Fri, 05 Apr 2019 02:33:46 +0000" then
, code 220
Got anticipated response
Sending HELO Friend1234.......(no response).............................................................................pm open,type:2 0".

It isn't the server.

mattlogue:
I really don't think my char definitions are causing it not to read a second time from client... any idea why it gets "Bytes in read buffer: [70]89Readchars: 220 mail.smtp2go.com ESMTP Exim 4.91 Fri, 05 Apr 2019 02:33:46 +0000" then
, code 220
Got anticipated response
Sending HELO Friend1234.......(no response).............................................................................pm open,type:2 0".

It isn't the server.

So where do you think the problem(s) is/are?