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'

What does it do: sends an email to 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-03 01:33:10