【问题标题】:How do I send a file as an attachment in bash script using sendmail?如何使用 sendmail 在 bash 脚本中将文件作为附件发送?
【发布时间】:2017-04-16 17:36:19
【问题描述】:

我正在使用 bash 脚本。我想用 sendmail 发送一封电子邮件,使用一个文件作为正文并添加另一个文件作为附件。我该怎么做呢?我已经弄清楚如何将第一个文件作为电子邮件正文发送...

#Send the email
cat - $TFILE1 <<END | /usr/sbin/sendmail -- $to_email
Subject: $subject
To: $to_email

END

但我不知道如何调整上述内容以包含第二个文件(比如它存储在 $TFILE2 中)作为附件?

【问题讨论】:

标签: bash shell sendmail attachment


【解决方案1】:

我倾向于使用uuencode 发送附件,但使用mailx(我以前从未使用过sendmail)。要使用uuencode,您需要安装sharutils

uuencodemailx 的语法如下:

uuencode attachment.txt attachment.txt | mailx -s "$subject" "$to_email"

【讨论】:

  • 我正在使用 Amazon Liniux。有没有办法安装 yoru 建议而不从头开始构建它(例如我可以安装的包)?我所在的环境没有设置所有的开发工具。
  • 我没用过 Amazon Linux,但你可以试试sudo yum install sharutils?
  • 嘿,我将如何扩展它以发送带有正文和附件的电子邮件?
  • 你可以试试:(echo "body text"; uuencode attachment.txt attachment.txt) | mailx -s "$subject" "$to_email"
猜你喜欢
  • 2017-01-06
  • 1970-01-01
  • 2023-03-19
  • 1970-01-01
  • 2012-07-29
  • 1970-01-01
  • 2018-07-27
  • 2011-07-20
  • 1970-01-01
相关资源
最近更新 更多