Search code examples
filesmtpattachmenttelnetemail-attachments

How can I send a file, for example "exe", with Telnet?


With smtp, i know the commands: "HELO", "MAIL FROM", "RCPT TO", "QUIT", but i don't know how can i attach one file. Anyone can help me ?

   telnet smtp.xxxx.xxxx 25 
helo xxxx.xxxx 
mail from: [email protected] 
rcpt to: [email protected] 
data 
subject: hi 
hello 
. 

quit

Solution

  • This is not something that can be easily done. You probably want to use a library (ex : in python) that will take care of formatting your email according to your needs.

    In very brief :

    • Sending an attachement requires the email to be formatted according to the MIME RFC
    • A MIME formatted message will use some delimiters to separate the different parts of the message (ex : a plain text part, an HTML part, an attachment part, etc...)
    • Each MIME part will be prefixed by a header detailing the part content
    • an attachment part will be identified by a "Content-disposition" header, as detailed in RFC 2183.
    • The representation of your file will have to be specified using the "Content-Transfer-Encoding" header, described in RFC 2045. A common way to encode files for mail transfer is base64.

    If you want to get an idea of how complex it is to generate an email with a valid attachment, you can use your email client to check the source of an email with an attachment (most email clients have this feature). That should eventually convince you to avoid doing this manually :)