SMTP pseudo code protocol
To send a message, the SMTP client and server conduct a "conversation." The SMTP protocol defines the formats of the messages making up the conversation and the order in which they occur.
establish connection
C: HELO (I would like to send an e-mail)
S: OK
C: MAIL (This e-mail is coming from xxx@yyy.xxx)
Loop until a valid user name is entered:
Check e-mail address format
End of loop
S: OK
C: RCPT (The recipient of the e-mail is xxx@yyy.zzz)
Loop until a valid user name is entered:
Check e-mail address format
End of loop
S: OK
C: DATA (I am ready to send you the e-mail message itself)
C: Send the message and end it with a CRLF.CRLF
C: send the text of the message including To, From, and Subject fields
C: CRLF.CRLF
S: OK -- the message is sent
C: Quit
S: Goodbye
end connection