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

I have a cron job that generates text files. I'd like these files to be sent as attachments to an email address. It's important that they show up as attachments in a multi-part MIME message and not just as text in the body of the email.

I have read about sendmail and the MAILTO parameter in /etc/crontab, but I am not able to write a simple example to build off of.

I do not have mutt, mail, or mailx installed on my server.

share|improve this question
up vote 2 down vote accepted

You could give nail a try. It allows you to specify an attachment.

In your script that generates these files you'd do something like the snippet below to deliver the file as an attachment to an email.

echo "body" | nail -s subject -a example-filename.txt 
share|improve this answer
I tried that it just seems to hang. Do I have to configure a mail server separately before I do this? – Manu R Nov 30 '10 at 22:26
Ah yes, I believe that will use the sendmail service running on your machine. – Dan R Nov 30 '10 at 22:27 It seems it could also alternatively support using an SMTP server that your machine has access to, you can specify this with the variable smtp – Dan R Nov 30 '10 at 22:31
You say the above hangs, which probably means that it's waiting for the e-mail boxy on stdin. Try putting "date |" in front of the "nail [...]" to feed the current date as stdin for the body. – Sean Reifschneider Dec 1 '10 at 11:03
Sean that worked beautifully! Thank you! Not in a million years would I have figured that out. – Manu R Dec 2 '10 at 3:19

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.