shellmailxuuencode

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."


Solution

  • 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.