Linux配置自动发邮件

安装服务

1
apt-get install sendmail sendmail-cf mailutils  ssmtp -y

发送邮件

1
echo "`/usr/sbin/ifconfig |grep inet6`" | mail -s "Mail from shell" xxxx@qq.com

配置源邮件

1
vim /etc/ssmtp/ssmtp.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=xxx@163.com

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.163.com:465 #固定模式
AuthUser=xxx@163.com #发件人的邮箱
AuthPass=xxx # 网易邮箱的授权码
UseTLS=Yes #认证打开
# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname
#hostname=pve.com

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
#FromLineOverride=YES

复杂脚本,IP发送不重复

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash
ip=`/usr/sbin/ifconfig |grep inet6`
echo "$ip" > ipnew.txt
diff_result=$(diff ip.txt ipnew.txt)
if [ ! -f "ip.txt" ]; then
echo "1" > ip.txt
fi
if [ -n "$diff_result" ]; then
\cp ipnew.txt ip.txt
echo "发送邮件"
echo "`cat ip.txt`" | mail -s "Mail from shell" 1441439636@qq.com
else
echo “内容重复”
fi

本文地址: https://github.com/maxzhao-it/blog/post/2bee6c61/