为 cron 作业设置“sendmail”标头 ([email protected])

为 cron 作业设置“sendmail”标头 ([email protected])

我在 AWS EC2 上使用 Ubuntu 14。我有一个非 root 用户。cron 作业完成后,将向中设置的地址crontab发送一封电子邮件。电子邮件发件人如下所示:MAILTOcrontab
[email protected]

我如何将“发件人”电子邮件更改为:

编辑-1: 根据贡献的评论,我telnet localhost 25在终端执行并返回:

220 ip-111-11-0-11.us-east-1.compute.internal ESMTP Sendmail 8.14.4/8.14.4/Debian-4.1ubuntu1
Tue, 5 Jul 2016 13:38:31 GMT
(No UCE/UBE) logging access from: localhost(OK)-localhost [127.0.0.1]

所以我的 MTA 是sendmail,我的问题变成:

我如何配置 sendmail 以便我的 cron 作业的电子邮件标头如上所示?

答案1

man 5 crontab会解决你的问题。其中部分内容如下:

An  active line in a crontab will be either an environment setting or a
   cron command.  An environment setting is of the form,

       name = value

   where the spaces around  the  equal-sign  (=)  are  optional,  and  any
   subsequent  non-leading  spaces  in  value  will  be  part of the value
   assigned to name.  The value string may be placed in quotes (single  or
   double, but matching) to preserve leading or trailing blanks.

   Several   environment   variables  are  set  up  automatically  by  the
   bcron-exec(8) program.  SHELL is set to /bin/sh, and LOGNAME, USER, and
   HOME are set from the /etc/passwd line of the crontab's owner.

   In  addition to LOGNAME, USER, HOME, and SHELL, bcron-exec(8) will look
   at MAILTO if it has any reason to send mail  as  a  result  of  running
   commands  in  ``this''  crontab.  If MAILTO is defined (and non-empty),
   mail is sent to the user so named.  If  MAILTO  is  defined  but  empty
   (MAILTO=""), no mail will be sent.  Otherwise mail is sent to the owner
   of the crontab.  This option is  useful  if  you  decide  on  /bin/mail
   instead  of  /usr/lib/sendmail  as your mailer when you install cron --
   /bin/mail doesn't do aliasing, and UUCP usually doesn't read its mail.

相关内容