html - 使用 CentOS 中的脚本发送 HTML 格式的电子邮件在 MS Outlook 中不起作用

标签 html linux outlook centos mailx

我正在尝试使用脚本从我的 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

enter image description here

展望

enter image description here

注意:

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/

相关文章:

java - iCal4J 生成的 Outlook 无法识别 .ics 文件中的时区

Python 脚本无法从 Outlook 获取最新邮件

ios - 使用 Phonegap Canvas 在 iOS 中自定义字体

linux - 在 Linux 中查找文件描述符 ulimit 的方法是什么

outlook - MS Graph API - 访问 token 验证失败

python - 从 txt 文件中删除重复的行

linux - 如何建立双向 SSH 隧道

javascript - 加载ajax模式时如何不重新加载

javascript - 如何将 iframe 的 src 设置为同一页面(使用不同的 anchor )

javascript - 在网页上将 PDF 文件显示为轮播,每页作为单独的幻灯片