Ole*_*ych 58 html linux email send
我需要发送html格式的电子邮件.我只有linux命令行和命令"mail".
目前已使用:
echo "To: address@example.com" > /var/www/report.csv
echo "Subject: Subject" >> /var/www/report.csv
echo "Content-Type: text/html; charset=\"us-ascii\"" >> /var/www/report.csv
echo "<html>" >> /var/www/report.csv
mysql -u ***** -p***** -H -e "select * from users LIMIT 20" dev >> /var/www/report.csv
echo "</html>" >> /var/www/report.csv
mail -s "Built notification" address@example.com < /var/www/report.csv
Run Code Online (Sandbox Code Playgroud)
但在我的邮件代理中我只得到普通/文本.
Dud*_*ude 51
这对我有用:
echo "<b>HTML Message goes here</b>" | mail -s "$(echo -e "This is the subject\nContent-Type: text/html")" foo@example.com
Run Code Online (Sandbox Code Playgroud)
Ole*_*nge 42
我的邮件版本没有--append,它对于echo -e \n-trick 来说太聪明了(它只是用空格替换\n).但它确实有-a:
mail -a "Content-type: text/html" -s "Built notification" address@example.com < /var/www/report.html
Run Code Online (Sandbox Code Playgroud)
Eri*_*ski 27
创建一个名为tmp.html的文件,并在其中添加以下行:
<b>my bold message</b>
Run Code Online (Sandbox Code Playgroud)
然后将所有这些粘贴到命令行中:(括号和全部).
(
echo To: youremail@blah.com
echo From: el@defiant.com
echo "Content-Type: text/html; "
echo Subject: a logfile
echo
cat tmp.html
) | sendmail -t
Run Code Online (Sandbox Code Playgroud)
邮件将被发送.消息显示为粗体而不是<b>标签.
来源:
如何使用bash命令"sendmail"发送html电子邮件?
问题是,当将文件重定向到"邮件"时,它仅用于邮件正文.您嵌入文件中的任何标题都会进入正文.
尝试:
mail --append="Content-type: text/html" -s "Built notification" address@example.com < /var/www/report.csv
Run Code Online (Sandbox Code Playgroud)
--append允许您向邮件添加任意标头,您应该在其中指定内容类型和内容处置.不需要在文件中嵌入To和Subject头文件,或者使用--append指定它们,因为您已经在命令行上隐式设置它们(-s是主题,而address@example.com自动成为To).
在OS X(10.9.4)上cat工作,如果您的电子邮件已经在文件中,则更容易:
cat email_template.html | mail -s "$(echo -e "Test\nContent-Type: text/html")" karl@marx.com
Run Code Online (Sandbox Code Playgroud)