【问题标题】:shell script - Sending mails to users without disclosing email addressesshell 脚本 - 在不透露电子邮件地址的情况下向用户发送邮件
【发布时间】:2019-03-19 11:10:08
【问题描述】:

我正在尝试在我的 shell 脚本中使用 mailx 向用户发送邮件,但不透露电子邮件地址。

这是我的一段代码 -

query1=$(sqlplus -s ${ORA_UID_PSWD} << 'EOF'
set heading OFF
SELECT cu.cntct_email
        FROM cm_user cu, cm_usertype ct
        WHERE trunc(cu.xprtn_dt) = trunc(sysdate) - 60
        AND cu.cm_user_id=ct.cm_user_id
        AND ct.user_type = 'E'
        AND cu.cntct_email is not null;
EOF
)
user_list1=$(echo "$query1" | tr '\n' ',' | sed 's:^.\(.*\).$:\1:')
echo $user_list1
echo -e "Hi,\nFYI.. Your password is expired 60 days ago. Please login and get it reset.\n\nThanks" |mailx -s "Password expired" -b $user_list1

我尝试使用 -b 选项(BCC),但我收到错误 -

不指定主要收件人的发送选项。

用法:

mailx -eiIUdEFntBDNHRV~ -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE
      -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users

任何人都知道我如何在不使用 To(Primary reciepnt) 的情况下发送

【问题讨论】:

    标签: shell mailx


    【解决方案1】:

    在没有收件人的情况下发送邮件的标准方法是使用group syntax 和一个空的地址列表。组的显示名称可用于向实际收件人提供有关其他人可能已收到消息的一些信息。

    一个常用的例子是:undisclosed-recipients: ;

    (在命令行使用时记得“引用”它)

    【讨论】:

      【解决方案2】:

      如果mailx 没有达到您的要求,您可以直接与sendmail 交谈。

      # Speculative; see below
      PATH=/usr/libexec:$PATH
      
      query1=$(sqlplus -s "$ORA_UID_PSWD" << 'EOF'
      set heading OFF
      SELECT cu.cntct_email
              FROM cm_user cu, cm_usertype ct
              WHERE trunc(cu.xprtn_dt) = trunc(sysdate) - 60
              AND cu.cm_user_id=ct.cm_user_id
              AND ct.user_type = 'E'
              AND cu.cntct_email is not null;
      EOF
      )
      # no need for further normalization of $query1 actually
      sendmail -oi $query1 <<'EOF'
      Subject: Password expired
      To: undisclosed-recipients:;
      
      Hi,
      FYI... Your password has expired 60 days ago.
      Please login and get it reset.
      
      Thanks
      EOF
      

      如果sendmail 不在您的PATH 中,则可能更新您的PATH(可能只是在此脚本中)所以它是。常见位置包括/usr/sbin/usr/libexec等;但如果这些没有帮助,请查阅您平台的文档以获得更好的猜测。

      不需要显式的Bcc: 标头;当您在命令行中指定收件人时,Sendmail 实际上会忽略标头。

      【讨论】:

        【解决方案3】:

        mailx 显然不能没有 TO,而是使用 mutt...

        例子:

        echo "My Message" | mutt -s "My Subject" -b addr1@domain.com -b addr2@domain.com -b addr3@domain.com
        

        【讨论】:

        • mutt 如果你已经安装了它当然很好;但是仅仅为了这个简单的任务安装它可能是多余的。
        猜你喜欢
        • 1970-01-01
        • 2011-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-18
        • 1970-01-01
        • 2014-01-01
        相关资源
        最近更新 更多