It then sends a command saying that it is starting the message. At that point, the other end stops treating what it sees as commands, and starts accepting the message. Your end then starts sending the text of the message. After that, both ends understand that your program is again sending commands. This is the simplest way to do things, and the one that most applications use.
File transfer is somewhat more complex.
The file transfer protocol involves two different connections. It starts out just like mail. However once the command to send data is sent, a second connection is opened for the data itself. It would certainly be possible to send the data on the same connection, as mail does. However file transfers often take a long time.