HOWTO: Sending email with attachment from the command line


The following one-liner sends email with attachment straight from the command line:

echo 'Here is the report from yesterday.' | uuencode /tmp/report.txt report-yesterday.txt | mail -s 'Report from yesterday' theboss@example.com

What does it do: sends an email to theboss@example.com with subject 'Report from yesterday'; the body contains 'Here is the report from yesterday.' and one attachment - report-yesterday.txt with identical content as /tmp/report.txt.
You will find this very useful when creating reports, summaries and even backups with automated cronjob for example.

 

No comments yet

Post a comment (fixed now)

Back to articles list      |     

This page was last modified on 2010-09-10 05:48:10