Is it possible to email attachments from the command line?
If possible, I'd like something as simple as:
mail -a myfile.txt -t firstname.lastname@example.org -s "Here's my file"
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:
except it won't go anywhere since one also needs a Mail Transfer Agent. Popular ones are:
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
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:
but you can't send same file as attachment as below:
Finally, I understood that only this format could send an attachment:
Funnily, the difference is existence of the "echo" command.
You may want to send a file from the shell, but otherwise use Thunderbird.
In this case, try
The command opens a mail compose window of a running thunderbird instance.
For a mail adressed to
There are two problems:
The attached file needs to be given by an absolute path, which is tedious in practice. That can be handeled by using
Also, the command is to long. Use a shell script or shell function, with four arguments:
With this function, the command becomes readable:
will open a thunderbird "Write" window with the attachment, and From, To, Subject, and body text filled in. It can be edited before sending it.
I wish to add another answer which is used to add body text along with the attachment. Cheers!!