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

Back to articles list

This page was last modified on 2024-03-26 20:19:59