通常,您希望使用 mail命令使用本地 MTA 发送消息(这将使用 SMTP 将消息发送到目的地,或者只是将消息转发到某个更强大的 SMTP 服务器,例如,您的 ISP)。如果您没有本地 MTA (尽管对于类 UNIX 系统来说省略一个 MTA 有点不寻常) ,那么您可以使用一些简约的 MTA,如 Ssmtp。
ssmtp非常容易配置。基本上,您只需指定提供商的 SMTP 服务器在哪里:
# The place where the mail goes. The actual machine name is required
# no MX records are consulted. Commonly mailhosts are named mail.domain.com
# The example will fit if you are in domain.com and you mailhub is so named.
mailhub=mail
set from = xxx@xxx.com #
set smtp = smtp.exmail.gmail.com #gmail's smtp server
set smtp-auth-user = xxx@xxx.com #sender's email address
set smtp-auth-password = xxxxxxx #get from gmail, not your email account passwd
set smtp-auth=login #because if it is not sent from an authorized account, email will get to junk mail list.
(2)
$ echo "Pls remember to remove unused ons topics!" | mail -s "waste topics" -a a.txt developer@xxx.com #send to group user 'developer@xxxx.com'
#!/bin/bash
REALVALUE=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=80
if [ "$REALVALUE" -gt "$THRESHOLD" ] ; then
mail -s 'Disk Space Alert' mailid@domainname.com << EOF
Your root partition remaining free space is critically low. Used: $REALVALUE%
EOF
fi