The 10 second delay is going to be a problem for you… it blocks the background tasks on the Spark Core and it will disconnect from the cloud…
Try creating a state machine that runs you through each step, but then drops out to continue through the main loop() once, then onto the next task.
int sendMail = false;
int sendMailState = 0;
int wait1 = 2000;
int wait2 = 2000; // play with these delays
setup() {
// setup your outputs...
}
loop() {
if (buttonState2 == HIGH && sendMail == false) {
digitalWrite(ledready, LOW);
digitalWrite(beep1, HIGH);
delay(200);
digitalWrite(beep1, LOW);
sendMail = true;
sendMailState = 0;
}
if( sendMail == true ) {
switch( sendMailState++ ) {
case 0:
client.connect(server, 25);
delay(wait1);
break;
case 1:
client.println("auth login");
delay(wait2);
break;
case 2:
client.println("dmx2cWFtb2c=");
delay(wait2);
break;
case 4:
client.println("passwordchangedforobviousreason");
delay(wait2);
break;
case 5:
client.println("mail from: john@doe.com");
delay(wait2);
break;
case 6:
client.println("rcpt to: you@you.com");
delay(wait2);
break;
case 7:
client.println("data");
client.println("This is line 1");
client.println("This is line 2");
client.println(".");
client.flush();
delay(wait);
break;
case 8:
digitalWrite(beep1, HIGH);
delay(200);
digitalWrite(beep1, LOW);
delay(50);
digitalWrite(beep1, HIGH);
delay(200);
digitalWrite(beep1, LOW);
sendMail = false;
break;
default:
sendMail = false;
break;
} // end switch
} // end send mail
} // end loop()