Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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 
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
    
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 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

 
discard

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.