【问题标题】:Using sendmail command while using uuencode to send attachment使用 uuencode 发送附件时使用 sendmail 命令
【发布时间】:2015-08-03 18:48:34
【问题描述】:

我正在尝试使用 sendmail 命令在 shell 脚本中发送电子邮件。我已成功发送附有 .txt 文件的电子邮件。这是我的工作代码示例:

       echo "Please enter a valid email address:"
       read EMAIL
       uuencode results.txt results.txt | sendmail $EMAIL

但是,当我尝试添加主题和正文时,例如:

       uuencode results.txt results.txt | sendmail $EMAIL<<EOF
       subject: Log file from today

       Test
       EOF

邮件正确发送,但没有附件。有任何想法吗?我是 C++ 和 VB 人。

谢谢。

【问题讨论】:

  • 第二个是将 uuencoded 数据通过管道传输到 sendmail 命令,但您基本上也使用 heredoc 覆盖了管道数据。换句话说,“这里有两个输入源,只关注第二个(heredoc)”
  • 我想我现在明白了你的解释 Marc 和 David 的例子。感谢您的所有帮助。

标签: linux shell unix centos


【解决方案1】:

为什么不把uuencode的结果放到一个变量中呢?假设 Bash:

ENCODED=`uuencode results.txt /dev/stdout`
echo "Please enter valid email address:"
read EMAIL
sendmail $EMAIL <<EOF
Subject: This is a test

Test file attached
--------------
$ENCODED
EOF

【讨论】:

    猜你喜欢
    • 2014-08-09
    • 2015-09-25
    • 2014-06-04
    • 2013-11-25
    • 2011-12-25
    • 2013-03-12
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    相关资源
    最近更新 更多