【问题标题】:Send email with html body and some attachment with sendmail使用 html 正文发送电子邮件,并使用 sendmail 发送一些附件
【发布时间】:2018-07-23 15:13:44
【问题描述】:

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

然而身体总是空的。

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
}

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

【问题讨论】:

  • 为什么是echo而不是cat &lt;&lt;-EOMail
  • @F.Hauri 你完全正确。这是来自stackoverflow.com/a/11725308/1507546 的快速复制/粘贴,对我不起作用。清洁它是下一步:)

标签: linux email sendmail suse


【解决方案1】:

我在玩了标题后发现了它,这对我有用。

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
}

【讨论】:

  • 你在哪里做这个,在 shell 上?
猜你喜欢
  • 2015-07-19
  • 2013-11-22
  • 2011-07-20
  • 2017-01-20
  • 2018-07-22
  • 2010-11-22
  • 2018-12-12
  • 2011-10-07
  • 2012-07-24
相关资源
最近更新 更多