Bash: Sending HTML with an attached file?

本小妞迷上赌 提交于 2019-12-11 20:41:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!