Tips, Tricks and Information for the Modern Technologist

Attach files to email via command line


Posted 4th December in Linux, Shell. 6 Comments

This is a pretty simple thing to do, once you’ve figured it out. You attach files using the following syntax:

1
uuencode filename1 filename2|mail user@domain.name

This will uuencode the file names, then pipe the output to the mail command, and mail to the user.



Dave Drager+ is the VP of Technology Development at Razor Servers (contact him for a great deal on dedicated servers). He has written previously for the technology blogs Lifehacker and MakeUseOf.


  • http://www.accessdataservices.com/phpesp/ gare

    How do you attach 2 files ?

    :0)
    Thanks for posting this solution!.

  • http://www.accessdataservices.com/phpesp/ gare

    How do you attach 2 files ?

    :0)
    Thanks for posting this solution!.

  • hyu

    uuencode f1 f1 > f1.uu
    uuencode f2 f2 > f2.uu
    echo “mail body” > mail.body
    cat mail.body f1.uu f2.uu | mail -s “test e-mail” you.e-mail@address.com

  • hyu

    uuencode f1 f1 > f1.uu
    uuencode f2 f2 > f2.uu
    echo “mail body” > mail.body
    cat mail.body f1.uu f2.uu | mail -s “test e-mail” you.e-mail@address.com

  • aaron

    ummm. i hate to burst your bubble but..

    nobody in this day/age should be using uuencode for anything.

    uuencoded attachments will be destroyed going through a large majority of email systems, especially when the mta involves ASCIIEBCDIC gateways, these will sever the 8th bit control codes.

    Theres a good explanation of the problems here:

    http://www.imc.org/ietf-822/old-archive1/msg00290.html

    And seriously. just use mimencode with base64, its understood by nearly every mail client and won’t get clipped by EBCDIC conversion.

  • aaron

    ummm. i hate to burst your bubble but..

    nobody in this day/age should be using uuencode for anything.

    uuencoded attachments will be destroyed going through a large majority of email systems, especially when the mta involves ASCIIEBCDIC gateways, these will sever the 8th bit control codes.

    Theres a good explanation of the problems here:

    http://www.imc.org/ietf-822/old-archive1/msg00290.html

    And seriously. just use mimencode with base64, its understood by nearly every mail client and won’t get clipped by EBCDIC conversion.