周围有许多不同版本的邮件。当您超出邮件-s的范围时,从1 @ address1到2 @ address2
对于某些mailx实现,例如从Ubuntu上的mailutils或Debian的bsd-mailx中实现,这很容易,因为有一个选项。
mailx -a 'Content-Type: text/html' -s "Subject" to@address
使用Heirloom Mailx,没有便捷的方法。插入任意标题的一种可能性是设置editheaders = 1并使用外部编辑器(可以是脚本)。
## Prepare a temporary script that will serve as an editor.
## This script will be passed to ed.
temp_script=$(mktemp)
cat <>"$temp_script"
1a
Content-Type: text/html
.
$r test.html
w
q
EOF
## Call mailx, and tell it to invoke the editor script
EDITOR="ed -s $temp_script" heirloom-mailx -S editheaders=1 -s "Subject" to@address <
~e
.
EOF
rm -f "$temp_script"
对于普通的POSIX mailx,我不知道如何获取标题。
如果您要使用任何邮件或mailx,请记住
即使在给定的Linux发行版中,这也无法移植。例如,Ubuntu和Debian都有mail和mailx的几种替代方案。
撰写邮件时,mail和mailx将以〜开头的行视为命令。如果将文本通过管道发送到邮件,则需要安排该文本不包含以〜开头的行。
如果仍然要安装软件,则最好安装比mail / Mail / mailx更可预测的内容。例如,mutt。使用Mutt,可以为输入中的大多数标头提供-H选项,但不能提供Content-Type,后者需要通过mutt选项进行设置。
mutt -e 'set content_type=text/html' -s 'hello' 'to@address'
或者,您可以直接调用sendmail。有多种版本的sendmail,但是它们都支持sendmail -t以最简单的方式发送邮件,从邮件中读取收件人列表。(我认为它们并不都支持Bcc :。)在大多数系统上,sendmail不在通常的$ PATH中,而是在/ usr / sbin或/ usr / lib中。
cat <
To: to@address
Subject: hello
Content-Type: text/html