4

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.

random
  • 450
  • 1
  • 9
  • 16
Manu R
  • 175
  • 2
  • 6

2 Answers2

3

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 
Dan R
  • 2,275
  • 1
  • 19
  • 27
  • 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
  • http://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 – Dan R 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 01 '10 at 11:03
  • Sean that worked beautifully! Thank you! Not in a million years would I have figured that out. – Manu R Dec 02 '10 at 03:19
  • +1 Ah yes, good call, edited the answer to show piping the body into nail – Dan R Dec 02 '10 at 03:24
1

the upstream for cron is here:

https://github.com/vixie/cron

i'd welcome patches to implement MIME for the stream i pipe into the "sendmail" wrapper. i'm already sending some headers, it would be a small matter to add the MIME headers and also close out the MIME attachment at EOF. there may be some hair involved if we have to "escape" the MIME markers that may appear inside the command's output, but i think that won't be necessary.

how to get your distro (or any distro) who imported cron ~20 years ago to merge against the upstream is a separate and much more difficult problem.

Paul Vixie
  • 1,144
  • 1
  • 11
  • 10