Oh Chin Boon Oh Chin Boon - 1 year ago 68
Bash Question

Sending simple message body + file attachment using Linux Mailx

I am writing a

shell script
to send an email using Linux
, the email must contain a file attachment and a message body.

Currently sending an email with an attachment:

output.txt | mail -s "Daily Monitoring" james@dell.com

I wish to add a message body. How should i?

Linux Mailx:

mail [-eIinv] [-a header] [-b addr] [-c addr] [-s subj] to-addr


The usual way is to use uuencode for the attachments and echo for the body:

(uuencode output.txt output.txt; echo "Body of text") | mailx -s 'Subject' user@domain.com