使用html正文发送电子邮件,使用sendmail发送一些附件

时间:2018-02-13 09:39:34

标签: linux email sendmail suse

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

然而身体总是空的。

class ConfigurationError < StandardError; end

def load_environment_config(gateway, trx_type)
  @config = YAML.load_file("config/#{env}_config.yml")[env.to_s.upcase]
  raise ConfigurationError, "Missing ..." unless @config[gateway]
end

为什么我的功能会发送空机身的电子邮件以及如何解决?

1 个答案:

答案 0 :(得分:2)

我在使用标题后想出来,这对我有用。

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
}