【问题标题】:sendmail: passing subject from shell scriptsendmail:从 shell 脚本传递主题
【发布时间】:2018-07-27 12:25:52
【问题描述】:

我正在使用模板在电子邮件正文中发送 html 文件。 现在我想做的是通过命令传递电子邮件的主题,就像在 shell 脚本中一样。

我的 html 文件如下所示:

To: test@test.com
From: noreply@test.com
Subject: subject will change
Content-Type: text/html; charset="us-ascii"
<html>
this is test email body
</html>

bash 脚本:

email=/usr/sbin/sendmail
report=/opt/html_report.html
template=/opt/email.template

$email -t < $final_report.html

【问题讨论】:

  • 接受建议;实际上 html 文件和标题(前四行)是使用 cat 合并的。电子邮件标题作为模板保存在文件中,并在每次生成新的 html 报告时合并。
  • 那么标题当前来自哪里?您可以使用 sed 将主题转换为您想要的内容,或者直接使用 echo 从 shell 脚本中写出 4 个标题行。
  • 你能演示一下吗?我的理解: echo To=test@test.com echo From: noreply@test.com echo Subject: 主题会改变 echo Content-Type: text/html; charset="us-ascii"
  • echo To: test@test,com &gt; final.html 然后 echo From: noreply@test,com &gt;&gt; final.html 等等。但是 sendmail 可能不是您要查找的程序...

标签: bash sendmail


【解决方案1】:

我不确定sendmail 程序是否是您要在此处使用的程序。来自sendmail 手册页:

Sendmail 不打算用作用户界面例程;其他程序提供用户友好的前端; sendmail 仅用于传递预先格式化的消息。

您可能想像这样使用/bin/mail

$ mail -s 'insert subject here' recipient@random.com < /opt/b2bpiv/email.template

键入 man mailmail --help 应该会列出您需要的所有命令行选项。

【讨论】:

  • 是否有在正文中发送 html 文档的选项;我也在看帮助。谢谢。
  • 由于您尝试从 bash 执行此操作,因此您的 html 文件实际上只需要 内容。主题、收件人和发件人由 /bin/mail 处理。内容文件可以包含您想要的任何文本。
  • mail -a "Content-type: text/html" -s "subject" test@test.com /report.html Content-type: text/html: 没有这样的文件或目录使用 -s 以 txt 格式发送报告。
  • 我的'mail'命令版本使用-a作为附件,看起来你的也是一样的(因此'没有这样的文件或目录')。我通常只将命令行邮件用于纯文本内容,但您可能会发现 mutt(另一个命令行电子邮件客户端)可以满足您的需求。请参阅 Wakaru44 对stackoverflow.com/questions/24010230/mailx-send-html-message的回答@
猜你喜欢
  • 2021-09-20
  • 1970-01-01
  • 2016-12-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-22
  • 2016-03-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多