Use ‘mutt’ to send email with attachment

The unix ‘mutt’ command can be used to send an email with attachment:

mutt -s "Test message" name@something -a files.tar < message.txt

where files.tar is the attached file, and message.txt is the file containing the message.

Subject to the email is added with the -s option. In this case:
-s “Test message”

name@something is the receiver email address

You can also do this:

echo "Message text" | mutt -s "Subject text" name@something -a files.tar


Why would you like to use a unix command to send an email with an attachment?
The answer is that in the case you want to automate some process, let us say, you would like to pack together some important files, and send them every Sunday to a certain person. It could be statistical data, for instance, and the person would like to have a report each Sunday so to read them on Monday before lunch.
You could then make a simple bash script that uses ‘tar’ to collect the files into a single tar-file. Then call on the unix ‘mutt’ command, and send the message together with the important tar-file. All can be automated by calling this bash script from cron (unix job scheduler)

Leave a Reply

Your email address will not be published. Required fields are marked *