
import processing.net.*; 

Client myClient; 
String dataIn;
int state;

final int IDLE = 1;
final int SAY_HELLO = 2;
final int HELLO_SAID = 3;
final int SAY_MSG_FROM = 4;
final int MSG_FROM_SAID = 5;

void setup() { 
  size(200, 200); 
  // Connect to the local machine at port 5204.
  // This example will not run if you haven't
  // previously started a server on this port.
  myClient = new Client(this, "smtp.unilim.fr", 25);
  state = IDLE;
} 

void mouseClicked() {
  String yourInput;
  switch(state)
  {
  case SAY_HELLO:
    yourInput = askString("Veuillez saisir le nom souhaité pour le HELLO ?");
    if (yourInput == null || yourInput.equals("")) {
      yourInput = "test-smtp.free.fr";
    }
    myClient.write("EHLO "+yourInput+"\r\n");
    state = HELLO_SAID;
    break;
  case SAY_MSG_FROM: 
    yourInput = askString("Veuillez saisir le nom d'expediteur souhaité ?");
    if (yourInput == null || yourInput.equals("")) {
      yourInput = "null@free.fr";
    }
    myClient.write("MAIL FROM: <"+yourInput+">"+"\r\n");
    state = MSG_FROM_SAID;
    break;
  }
}

void draw() { 
  if (myClient.available() > 0) { 
    dataIn = myClient.readString();
    switch(state)
    {
    case IDLE: 
      state = SAY_HELLO;
      break;
    case HELLO_SAID: 
      state = SAY_MSG_FROM;
      break;
    }
    println(dataIn);
  }
} 
