【问题标题】:Send email with body and attachment with mailx使用 mailx 发送带有正文和附件的电子邮件
【发布时间】:2016-08-16 09:01:34
【问题描述】:

如何使用 mailx 发送带有正文和附件的电子邮件?

此代码将发送一封带有正文的电子邮件:

cat $body | tr -d \\r | mailx -s "SUBJECT" foo@bar.com

tr -d \\r 在这种情况下是必要的,因为如果正文没有通过tr 进行管道传输,它将作为 .bin 附件发送(对于这个特定的正文)。在此处找到以 .bin 形式发送的正文的解决方案:Use crontab job send mail, The email text turns to an attached file which named ATT00001.bin

我尝试将-f $attachment 放在主题之后,但出现错误More than one file given with -f,并且命令将无法运行。

【问题讨论】:

    标签: bash sh mailx


    【解决方案1】:

    来自mailx 的手册页:

    -a file
              Attach the given file to the message.
    

    -f 使 mailx 处理文件,就好像它是在标准输入上提供的一样,因此您遇到了错误,因为您通过标准输入和文件向mailx 提供数据。

    【讨论】:

    • 这就是答案。我很尴尬。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2020-06-02
    • 2018-07-24
    • 2012-12-31
    • 1970-01-01
    • 2015-09-09
    相关资源
    最近更新 更多