I am writing a shell script
to send an email using Linux Mailx
, the email must contain a file attachment and a message body.
Currently sending an email with an attachment:
output.txt | mail -s "Daily Monitoring" [email protected]
I wish to add a message body. How should i?
Linux Mailx:
mail [-eIinv] [-a header] [-b addr] [-c addr] [-s subj] to-addr
Method 2 : -a switch in mailx command The -a options is easier to use that the uuencode command. The above command will print a new blank line. Type the body of the message here and press [ctrl] + [d] to send. This will attach the file to the outbound email correctly with proper Content-Type and boundary headers.
To send an attachment from the email, use uuencode command.
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' [email protected]
For Solaris and AIX, you may need to put the echo
statement first:
(echo "Body of text"; uuencode output.txt output.txt) | mailx -s 'Subject' [email protected]
The best way is to use mpack!
mpack -s "Subject" -d "./body.txt" "././image.png" mailadress
mpack - subject - body - attachment - mailadress
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With