Thursday 2 January 2020

shell - Cannot attach file and include a body while sending an email in Linux




The command below will send an email with a Subject and Body, but no Attachment. If I remove < /usr/tmp/BODY_OF_EMAIL I receive the email with Subject and Attachment, but no Body.



cat /usr/tmp/ATTACHMENT.xls | uuencode ATTACHMENT.xls | mailx -s "Subject of email!" emailaddress@company.com < /usr/tmp/BODY_OF_EMAIL



/usr/tmp/BODY_OF_EMAIL contains the text "Email Body."


Answer



Using mailx:



(cat /usr/tmp/BODY_OF_EMAIL;
echo;
uuencode ATTACHMENT.xls < /usr/tmp/ATTACHMENT.xls ) |
mailx -s "Subject of email!" emailaddress@company.com



Using nail:



nail -s "Subject of email!" -a /usr/tmp/ATTACHMENT.xls emailaddress@company.com < /usr/tmp/BODY_OF_EMAIL


The nail mailer is sometimes installed as mail, but it understands MIME, for real attachments.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...