How do you send an email with both a body and attachment with mailx?
This code will send an email with a body:
cat $body | tr -d \\r | mailx -s "SUBJECT" foo@bar.com
tr -d \\r
is necessary in this case because if the body is not piped through tr
, it will send as a .bin attachment (for this particular body). Found the solution to the body sending as .bin here: Use crontab job send mail, The email text turns to an attached file which named ATT00001.bin
I have tried putting -f $attachment
after the subject, but am given the error, More than one file given with -f
, and the command will not run.