问题
I'm looking for a way to send an HTML email from bash with an attached file. I've tried the following line, but it doesn't work 100%. The below line sends an HTML email, but there is no attached file:
( cat body.html ; uuencode in-attachfile.txt out-attachfile.txt ) | mail -s "$(echo -e "my subject\nContent-Type: text/html")" foo@example.com
If I remove the Content-Type: text/html
to indicate this is an HTML email then the attachment works:
( cat body.html ; uuencode in-attachfile.txt out-attachfile.txt ) | mail -s "$(echo -e "my subject")" foo@example.com
How can I have both?
Thank you
回答1:
Try this:
( cat body.html; uuencode in-attachfile.txt out-attachfile.txt ) | mail -s "my subject" -a "Content-Type: text/html" foo@example.com
You may want to send the attachment using MIME (via mutt, for example). See this for more information.
来源:https://stackoverflow.com/questions/10479340/bash-sending-html-with-an-attached-file