gpt4 book ai didi

linux - 使用 sendmail 发送带有 html 正文和一些附件的电子邮件

转载 作者:太空宇宙 更新时间:2023-11-04 09:15:12 25 4
gpt4 key购买 nike

关注此https://stackoverflow.com/a/11725308/1507546 ,我可以发送一封带有一个附件的电子邮件。

然而 body 总是空的。

notify() {
local mailpart="$(uuidgen)"
local mailpartBody="$(uuidgen)"
local subject="subject"
local attachment='tmp/attachment.txt'


(
echo "From: no-reply@company.com"
echo "To: ${authors}"
echo "Subject: ${subject}"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary=\"${mailpart}\""
echo ""
echo "--${mailpart}"
echo "Content-Type: multipart/alternative; boundary=\"${mailpartBody}\""
echo ""
echo "--${mailpartBody}"
echo "Content-Type: text/plain; charset=ISO-8859-1"
echo "You need to enable HTML option for email"
echo "--${mailpartBody}"
echo "Content-Type: text/html; charset=ISO-8859-1"
echo "Content-Disposition: inline"
echo "<h1>hello world!!</h1>"
echo "--${mailpartBody}--"

echo "--${mailpart}"
echo 'Content-Type: text/plain; name="'$(basename ${attachment})'"'
echo "Content-Transfer-Encoding: uuencode"
echo 'Content-Disposition: attachment; filename="'$(basename ${attachment})'"'
echo ""
uuencode ${attachment} $(basename ${attachment})
echo "--${mailpart}--"
) | sendmail -t
}

为什么我的函数发送的电子邮件正文为空,如何解决?

最佳答案

我在玩了标题之后想通了,这对我有用。

notify() {
local mailpart="$(uuidgen)"
local mailpartBody="$(uuidgen)"
local subject="subject"
local attachment='tmp/attachment.txt'


(
echo "From: no-reply@company.com"
echo "To: ${authors}"
echo "Subject: ${subject}"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary=\"${mailpart}\""
echo ""
echo "--${mailpart}"
echo ""
echo "Content-Type: text/plain; charset=ISO-8859-1"
echo "Content-Disposition: inline"
echo ""
echo "<h1>hello world!!</h1>"

echo "--${mailpart}"
echo 'Content-Type: text/plain; name="'$(basename ${attachment})'"'
echo "Content-Transfer-Encoding: uuencode"
echo 'Content-Disposition: attachment; filename="'$(basename ${attachment})'"'
echo ""
uuencode ${attachment} $(basename ${attachment})
echo "--${mailpart}--"
) | sendmail -t
}

关于linux - 使用 sendmail 发送带有 html 正文和一些附件的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48763611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com