This question already has an answer here:
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" 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
You can try this:
The best way is to use mpack!
mpack -s "Subject" -d "./body.txt" "././image.png" mailadress
mpack - subject - body - attachment - mailadress
The usual way is to use
uuencode
for the attachments andecho
for the body:For Solaris and AIX, you may need to put the
echo
statement first:Try this it works for me:
Johnsyweb's answer didn't work for me, but it works for me with Mutt:
On RHEL Linux, I had trouble getting my message in the body of the email instead of as an attachment . Using od -cx, I found that the body of my email contained several /r. I used a perl script to strip the /r, and the message was correctly inserted into the body of the email.
The text file body.txt contained the char \r, so I used perl to strip \r.
This is success.pl