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 a number of serverfault questions 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.

Any help would be appreciated.

link|improve this question
feedback

1 Answer

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 you@example.com 
link|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. – Daniel Rucci Nov 30 '10 at 22:27
linux.die.net/man/1/nail 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 – Daniel Rucci Nov 30 '10 at 22:31
1  
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
show 1 more comment
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.