How can I email an attachment from the command line

Of all the mail user agents in the Ubuntu repository, it appears that mutt is the command-line MUA that is blessed with Long Term Support.

According to the manual, you can do something exactly like:

mutt -a myfile.txt -s "Here's my file" -- [email protected]

except it won't go anywhere since one also needs a Mail Transfer Agent. Popular ones are:

  • the venerable sendmail
  • postfix
  • exim4
  • qmail
  • nullmailer

and the only ones that Canonical seems to support are postfix (thanks for the correction Steve) and exim4.

One could also say that xdg-email is also a proper Ubuntu MUA, but it is a bare-bones front end which only executes your preferred MUA on your behalf.

If you'd like advice on which MTA might be suitable for your use, perhaps open another question here.


I had bad trouble with sending attachment files, too. When I sent an email without attachment, it was successful but was not with attachment. This problem was existent with sendemail, mutt, mail, mailx , uuencode commands.

Fortunately, It was solved funnily. I use Gmail for sending email. You can configure your gmail for sending emails via commands in terminal as declared at http://www.linuxandlife.com/2013/01/send-email-from-linux-terminal.html .

You can send a text email using:

mail -s "hello" [email protected] < /home/masoud/YOURFILE.txt 

but you can't send same file as attachment as below:

mail -s "hello" [email protected] -a /home/masoud/YOURFILE.txt

or:

mail -s "hello" -a /home/masoud/YOURFILE.txt [email protected]

Finally, I understood that only this format could send an attachment:

echo "your message here" | mail -s "title" -a /home/masoud/YOURFILE.txt [email protected]

Funnily, the difference is existence of the "echo" command.

Update: 201808

Seems that the -a option has been changed with Uppercase -A for attachment now. The -a seems to be for changing header according to doc


I found that the command and parameters have been changed recently.

If your want to send your attachments with this command:

mail -s "your subject" [email protected] -A /your/attachment/absolute/path < /home/you/message.txt

The option attachment should be -A which is CAPITAL A.