29

有人有可用的演示吗?

Sendmail 据说不可扩展,但它是免费的,所以我决定暂时先使用它:)

4

8 回答 8

56

以下作品:

(
echo "From: ${from}";
echo "To: ${to}";
echo "Subject: ${subject}";
echo "Content-Type: text/html";
echo "MIME-Version: 1.0";
echo "";
echo "${message}";
) | sendmail -t

有关与兼容的msmtpsendmail进行故障排除,请参阅:

于 2013-04-08T13:01:47.263 回答
18

如果我理解正确,您想使用 linux sendmail 命令以 HTML 格式发送邮件。此代码适用于 Unix。请试一试。

echo "From: me@xyz.com
To: them@xyz.com
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary='PAA08673.1018277622/server.xyz.com'
Subject: Test HTML e-mail.

This is a MIME-encapsulated message

--PAA08673.1018277622/server.xyz.com
Content-Type: text/html

<html> 
<head>
<title>HTML E-mail</title>
</head>
<body>
<a href='http://www.google.com'>Click Here</a>
</body>
</html>
--PAA08673.1018277622/server.xyz.com
" | sendmail -t

有关 sendmail 配置详情,请参阅此链接。希望这可以帮助。

于 2009-08-26T08:24:14.970 回答
5

我知道您要求 sendmail 但为什么不使用默认邮件?它可以轻松发送 html 电子邮件。

适用于:RHEL 5.10/6.x 和 CentOS 5.8

例子:

cat ~/campaigns/release-status.html | mail -s "$(echo -e "Release Status [Green]\nContent-Type: text/html")" to.address@company.com -v

代码共享:http : //www.codeshare.io/8udx5

于 2014-09-18T06:11:45.233 回答
4

此页面应该有所帮助 - http://www.zedwood.com/article/103/bash-send-mail-with-an-attachment

它包括一个脚本,用于发送带有 MIME 附件的电子邮件,即包含 HTML 页面和图像。

于 2009-08-26T08:13:12.357 回答
3

-一个选项?

参照。手册页:

-a file
          Attach the given file to the message.

结果:

Content-Type: text/html: No such file or directory
于 2017-08-18T14:00:17.233 回答
3

在http://senthilkl.blogspot.lu/2012/11/how-to-send-html-emails-using-sendemail.html找到解决方案

sendEmail -f "oracle@server" -t "name@domain.com" -u "Alert: Backup complete" -o message-content-type=html -o message-file=$LOG_FILE  -a $LOG_FILE_ATTACH 
于 2018-03-08T12:01:35.297 回答
2

使用mail跟进上一个答案:

通常情况下,客户端邮件程序会解释一个人的 html 输出,这可能不会使用固定宽度的字体来格式化内容。因此,您格式良好的 ascii 对齐方式变得一团糟。要按照上帝的意图发送老式的固定宽度,试试这个:

{ echo -e "<pre>"
echo "Descriptive text here."
shell_command_1_here
another_shell_command
cat <<EOF

This is the ending text.
</pre><br>
</div>
EOF
} | mail -s "$(echo -e 'Your subject.\nContent-Type: text/html')" to.address@company.com

您不一定需要“此处的描述性文字”。行,但我发现有时第一行可能会根据其内容导致邮件程序以您不希望的方式解释文件的其余部分。首先尝试使用简单描述性文本的脚本,然后以您想要的方式微调输出。

于 2014-11-18T16:26:14.153 回答
-2

-a 选项使用起来更简单:

cat ~/campaigns/release-status.html | mail -s "Release Status [Green]" -a "Content-Type: text/html" to.address@company.com
于 2015-12-04T10:23:37.857 回答