Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to attach a file to an email from the CLi using mail?

I am having trouble finding this feature on the manpage.

share|improve this question
up vote 2 down vote accepted

The best way to do this is generally to use mutt instead:

$ mutt -s "test subject" -a test.jpg < test.txt

mutt is available on most unix-like platforms these days and usually comes installed in the base OS.

Your other option is to uuencode the file and send it through mail:

    $ uuencode test.jpg test.jpg | mail

as explained here.

share|improve this answer

can try

mail -s "Attached file" <<EOF                 

~| uuencode $HOME/filename.txt filename.txt


atleast with gnus mailutils see

share|improve this answer

If you're restricted to using "mail", then you can use uuencode to encode the file. I think the modern mail clients still support uunecode :) uuencode file.jpg file.jpg | mail -s "pic" "" File named is passed twice (first is the local file to be encoded and second is the file name as it will be extracted on the remote system).

Otherwise, you can use mutt or metamail to send MIME encoded mails. You can use both from command line.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.