安裝mailx、exim4
apt-get install exim4-daemon-light mailutils
dpkg-reconfigure exim4-config
General type of mail configuration:
│ internet site; mail is sent and received directly using SMTP │
│ mail sent by smarthost; received via SMTP or fetchmail │
│ mail sent by smarthost; no local mail │
│ local delivery only; not on a network │
│ no configuration at this time
System mail name:
cowman.no-ip.org
IP-addresses to listen on for incoming SMTP connections:
127.0.0.1 ; ::1
Other destinations for which mail is accepted:
(null)
Machines to relay mail for:
(null)
IP address or host name of the outgoing smarthost:
smtp.gmail.com::587
Hide local mail name in outgoing mail?
YES NO
Keep number of DNS-queries minimal (Dial-on-Demand)?
YES NO
Delivery method for local mail:
│ mbox format in /var/mail/ │
│ Maildir format in home directory │
Split configuration into small files?
YES NO
Root and postmaster mail recipient:
(null)
vim /etc/exim4/passwd.client 加入
*:帳號:密碼
測試寄信
echo "This is a test." | mail -s Testing cowman.chiang@gmail.com
ssh登入時寄發通知信件
echo 'ALERT - Shell Access (Git) on:'
date
who
| mailx -A gmail -s "Alert: Shell Access from who | cut -d'(' -f2 | cut -d')' -f1
" cowman.chiang@gmail.com > /dev/null 2>&1