When we type something in a text file or suppose that I'm sending an email to my friend with an attachment inside the email. In both cases of text file and email. What is happening first? Is that text/attachment converting to ASCII OR BINARY first? When we type something is that computer takes it in binary or ASCII?
The SMTP protocol does not encode the size of the message in the protocol. The end of the message is reached when a single dot
. is received on a line of its own. So, the protocol doesn't allow transmission of any data that contains a newline, a dot and another newline in sequence.
In practice, it is even more restricted, as several of the old mailer daemons did not handle non-ASCII characters well, so people used uuencode to turn binary data into ASCII. The base64 encoding is a more efficient variant of that, and this is what current mail clients use to prepare binary data that contains non-ASCII characters for transmission.