I am trying to send multiple attachments but not working using mpack/mailx
example below
#!/bin/bash
fileName1="/tst/test.xls"
fileName2="/tst2/test1.csv"
mailBodyFile="/tmp/test.tmp"
MailTo="[email protected]"
TodayDate=$(date)
recordCount="`cat ${fileName1} | wc -l`"
mailSubject="Test ${TodayDate}"
if [[ ${recordCount} -gt 1 ]]
then
echo -e "Test,\n\nTest123" > ${mailBodyFile}
mailx -s "${mailSubject}" -a ${fileName1} ${fileName2} -d ${mailBodyFile} ${MailTo}
else
echo -e "xyz" > ${mailBodyFile}
fi
is there another option to send multiple attachment files?
the script hangs when using mpack (multiple attachments not supported).
You can attach multiple files with mailx, you just need to proceed each filename with the -a option. Also, -d puts mailx into "debug" mode, it doesn't allow you to specify a file as the body of the message. You could just "cat" the body of the message to mailx, or use standard redirection. The end results would be something like:
mailx -s "${mailSubject}" -a "${fileName1}" -a "${fileName2}" -d "${MailTo}" < "${mailBodyFile}"