I am required to send an email using shell script.
The body of the email consists of a hyperlink. The email should also have an pdf attachment.
I have tried using mailx and sendmail. Facing the following issue.
With mailx,
EMAIL_TO_USERS=/tmp/test.email
touch $EMAIL_TO_USERS
pdf_to_attach=sample.pdf
echo " Hello " > $EMAIL_TO_USERS
echo " This is test url www.example.com " >> $EMAIL_TO_USERS
cat $EMAIL_TO_USERS | mailx -a $pdf_to_attach -r [email protected] -s "Subject"
[email protected]
rm $EMAIL_TO_USERS
This works fine with the attachment but the hyperlink gets expanded in the email that i receive. Hence i tried with sendmail
With sendmail,
ATTACH="sample.pdf"
(
echo "To: [email protected]"
echo "Subject: hello"
echo "Content-Type: text/html"
echo
echo "<html><b><font size='7'>H</font>ello</b></html>"
echo "<html><body><a href="www.example.com">www.example.com</a></body></html>"
echo 'Content-Type: application/pdf; name="'$(basename $ATTACH)'"';
echo "Content-Transfer-Encoding: base64";
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"';
echo
base64 example.pdf
) | /usr/sbin/sendmail -t
This works great with the hyperlink but i cant find the attachment. The attachment is converted to some random text in the email body.
I cant use mutt because its not available in the server i work on.
Please help!