I am trying to create a simple send mail function for a custom app created with the Qt framework in C++. I am very close just at the point where SMTP is trying to authenticate and can't for the life of me to get this to work. Here is what I am working with
do {
responseLine = socket->readLine();
response += responseLine;
}
while ( socket->canReadLine() && responseLine[3] != ' ' );
responseLine.truncate( 3 );
if ( state == Init && responseLine[0] == '2' ) {
// banner was okay, let's go on
*t << "HELO there\r\n";
t->flush();
state = Auth;
} else if (state == Auth && responseLine[0] == '2') {
*t << "STARTTLS\r\n";
*t << "AUTH PLAIN\r\n";
t->flush();
state = User;
} else if (state == User && responseLine[0] == '2') {
*t << "username\r\n";
t->flush();
state = Pass;
} else if (state == Pass && responseLine[0] == '2') {
*t << "pass\r\n";
t->flush();
state = Mail;
} else if ( state == Mail && responseLine[0] == '2' ) {
// HELO response was okay (well, it has to be)
*t << "MAIL FROM: " << from << "\r\n";
t->flush();
state = Rcpt;
} else if ( state == Rcpt && responseLine[0] == '2' ) {
*t << "RCPT TO: " << rcpt << "\r\n"; //r
t->flush();
state = Data;
} else if ( state == Data && responseLine[0] == '2' ) {
*t << "DATA\r\n";
t->flush();
state = Body;
} else if ( state == Body && responseLine[0] == '3' ) {
*t << message << "\r\n.\r\n";
t->flush();
state = Quit;
} else if ( state == Quit && responseLine[0] == '2' ) {
*t << "QUIT\r\n";
t->flush();
// here, we just close.
state = Close;
emit status( tr( "Message sent" ) );
} else if ( state == Close ) {
deleteLater();
return;
} else {
// something broke.