我正在尝试使用脚本从我的 linux CentOS 服务器 (Amazon EC2) 发送格式化的 HTML 电子邮件。我将它发送到一个 gmail 帐户和一个工作电子邮件帐户,我们使用 Outlook 2016。
电子邮件在 gmail 中格式化正常,但在 Outlook 中它也打印出完整的 html 标签。
我的脚本
#!/bin/bash
CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
EMAILS="myGmailAddressa@gmail.com, myWorkEmail@company.com"
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" > /tmp/testemail.html
echo "<html" >> /tmp/testemail.html
echo "<head>" >> /tmp/testemail.html
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" >> /tmp/testemail.html
echo "</head>" >> /tmp/testemail.html
echo "<body style=\"background-color:#99ccff;\" \"width:600px;\">" >> /tmp/testemail.html
echo "<table>" >> /tmp/testemail.html
echo "<tr style=\"height:30px;\">" >> /tmp/testemail.html
echo "<td><strong>Current Disk Size:</strong></td>" >> /tmp/testemail.html
echo "<td>$CURRENT</td>" >> /tmp/testemail.html
echo "</tr>" >> /tmp/testemail.html
echo "</table>" >> /tmp/testemail.html
echo "</body>" >> /tmp/testemail.html
echo "</html>" >> /tmp/testemail.html
(cat /tmp/testemail.html) | mail -s "$(echo -e "Test 7 MIME- HTML Formatted OUTPUT \nMIME-Version: 1.0 \nContent-Type: text/html")" $EMAILS EOF
这是我运行脚本后 testemail.html
文件的内容。
testemail.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="background-color:#99ccff;" "width:600px;">
<table>
<tr style="height:30px;">
<td><strong>Current Disk Size:</strong></td>
<td>85</td>
</tr>
</table>
</body>
</html>
Gmail
展望
注意:
I know I can just forward the emails from gmail to my work email but that is NOT what I want to do. I know this will help others so I want it to be done correct.
有没有人以前遇到过这个问题和/或有解决方法。
G
最佳答案
你的脚本违反了很多邮件 rfc,所以预期的结果是你的邮件正文被破坏了。没时间解释了,试试用 mutt 来构建正确的消息正文:
cat /tmp/testemail.html | mutt \
-e "set content_type=text/html" \
-e "set from=your@address.com" \
-e "set realname=daemon" \
-e "set send_charset=utf-8" \
-s "test subject" \
myGmailAddressa@gmail.com \
myWorkEmail@company.com
不要忘记在使用前安装它:yum install -y mutt
。
关于html - 使用 CentOS 中的脚本发送 HTML 格式的电子邮件在 MS Outlook 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36751301/