Oh Chin Boon Oh Chin Boon - 2 years ago 146
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

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download