Using mutt to send a message with attachment

Well…this was kind of a pain to get working, for an idiot like me. I wanted to get a tarred version of a particular log file via email – as an attachment – and I had no idea where to start. In other words, I wanted to have an email sent to me, with an attachment, using an automated (cron driven) script. The following little script, which uses mutt, did the trick. I found the info on the net, somewhere. The script, below, deletes an old .tar file and creates a new one, then performs the mail function (the important part). The “message.txt” file is the body of the email. A big thank you to someone, somewhere – I can’t recall where I finally dug this up.



Okay – so on Ubuntu 10 (the above was on Centos 5.5, as I recall) there are some significant differences. For one thing, with newer versions of this thing the attachment info must come after the email address. Also, when I downloaded mutt via apt it also installed postfix. Apparently, mutt wants to use Postfix, although postfix does not start at boot time – so there’s no conflict with my Qmail setup. However, my new script has to shutdown Qmail, for an instant, and start and stop Postfix to make all of this work. Here’s an example:


Okay…….ack! I have no idea what’s going on, but, the above worked off and on…… The following seems to be a far more reliable method: