2

我目前正在使用 mailx 从我的脚本中发送 html 格式的邮件:

cat body.html | /usr/bin/mailx -a "From: Me <me@domain>" -a "Content-type: text/html" -s "My subject" $RECIPIENTS

现在我想添加一个附件(png 图像),但我不知道怎么做。在迁移到 mutt 或其他东西之前,我想尝试使用 mailx。非常感谢

4

2 回答 2

1

如果您的要求很简单,则可以使用裸 Sendmail。这不是我特别推荐的,但既然你想避免mutt......

# Now that we actually concatenate two files (well, stdin and a file),
# we are no longer eligible for a Useless Use of Cat Award
( cat - body.html <<HERE
Subject: My subject
Mime-Version: 1.0
Content-type: multipart/related; boundary="foooobar"

--foooobar
Content-type: text/html

HERE

cat <<HERE

--foooobar
Content-type: image/png
Content-disposition: inline
Content-transfer-encoding: base64

HERE

base64 image.png

echo; echo '--foooobar--' ) | sendmail -oi $RECIPIENTS

我确实希望有一个简单的标准实用程序来解决这个问题,但可惜的是,有很多,或多或少相互不兼容和模糊不清。同样,如果您可以使用mutt,那可能是您希望得到的最广泛支持和最标准的工具。

于 2014-03-10T18:42:14.750 回答
1

尝试这个:

uuncode input_file2.jpg attachment2.jpg >>tempfile
cat tempfile | mailx -s "subject" <email>

Uuencode 读取文件(或默认为标准输入)并将编码版本写入标准输出。编码仅使用打印 ASCII 字符并包括文件的模式和 uudecode 使用的操作数名称。如果名称是 /dev/stdout,则结果将被写入标准输出。默认情况下,将使用标准 UU 编码格式。如果在命令行上给出了选项 -m,则使用 base64 编码。

于 2015-04-27T00:01:52.447 回答