-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.sh
132 lines (115 loc) · 4.49 KB
/
mail.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# 功能选择
format_check(){
echo -e "\033[34m 中文:{ 0.配置发送邮箱 1.单发邮箱测试 2.单发送邮箱提醒设置 3.群发邮箱测试 4.群发邮箱提醒设置 5或其他:退出 } English:{0.Configure sending mailbox 1.Single email test 2.Single send mailbox reminder settings 3.group email test 4.group email reminder settings 5 or ohter: exit } \033[0m"
read -p "Please select the number:" oper1
}
# Ubuntu依赖安装
installMailboxDependenciesUbuntu(){
`chmod 777 /etc/apt/sources.list`
isConf=`cat /etc/apt/sources.list | grep "xenial main universe"`
if [[ ! -n "$isConf" ]];then
`"deb http://cz.archive.ubuntu.com/ubuntu xenial main universe" >> /etc/apt/sources.list`
fi
`sudo apt-get update`
`sudo apt-get install heirloom-mailx -y`
}
# centos依赖安装,待完善
installMailboxDependenciesCentos(){
echo "centos"
}
# 配置发送方邮箱服务
configureMailbox(){
from=`awk -F '=' '/\[sendOutMailConf\]/{a=1}a==1&&$1~/set from/{print $2;exit}' $mailConif`
setFrom="set from=$from"
`sed -i "s/^.*set from.*$/$setFrom/" /etc/s-nail.rc`
smtp=`awk -F '=' '/\[sendOutMailConf\]/{a=1}a==1&&$1~/set smtp/{print $2;exit}' $mailConif`
setSmtp="set smtp=$smtp"
`sed -i "s/^.*set smtp.*$/$smtp/" /etc/s-nail.rc`
user=`awk -F '=' '/\[sendOutMailConf\]/{a=1}a==1&&$1~/set smtp-auth-user/{print $2;exit}' $mailConif`
setUser="set smtp-auth-user=$user"
`sed -i "s/^.*set smtp-auth-user.*$/$setUser/" /etc/s-nail.rc`
password=`awk -F '=' '/\[sendOutMailConf\]/{a=1}a==1&&$1~/set smtp-auth-user/{print $2;exit}' $mailConif`
setPass="set smtp-auth-password=$password"
`sed -i "s/^.*set smtp-auth-password.*$/$setPass/" /etc/s-nail.rc`
auth="set smtp-auth=login"
`sed -i "s/^.*set smtp-auth.*$/$auth/" /etc/s-nail.rc`
}
# 单个发送邮箱测试
onlySendMailTest(){
single_mailbox=`awk -F '"' '/\[recipientMailConf\]/{a=1}a==1&&$1~/single_mailbox/{print $2;exit}' $1`
`bash $3/sendMail.sh $2 $single_mailbox`
}
# 单个邮箱发送提醒设置
onlySendMailSet(){
`chmod 777 /var/spool/cron/crontabs/root`
isConf=`cat /var/spool/cron/crontabs/root | grep "only_mail"`
only_mailbox=`awk -F '"' '/\[recipientMailConf\]/{a=1}a==1&&$1~/single_mailbox/{print $2;exit}' $1/remindMail.conf`
if [[ ! -n "$isConf" ]];then
sed -ie '/only_mail.sh/d' /var/spool/cron/crontabs/root
fi
time_num=`date -d "1 hour" +"%M"`
echo "$time_num * * * $1/only_mail.sh" >> /var/spool/cron/crontabs/root
`bash $1/sendMail.sh $2 $only_mailbox`
}
# 群发邮件测试
groupSendMailTest(){
group_mailbox=`awk -F '"' '/\[recipientMailConf\]/{a=1}a==1&&$1~/group_mailbox/{print $2;exit}' $1`
for i in $group_mailbox
do
`bash $3/sendMail.sh $2 $i`
done
}
# 群发邮箱提醒设置
groupSendMailSet(){
`chmod 777 /var/spool/cron/crontabs/root`
isNull=`cat /var/spool/cron/crontabs/root | grep "group_mail.sh"`
if [[ ! -n "$isConf" ]];then
sed -ie '/group_mail.sh/d' /var/spool/cron/crontabs/root
fi
echo "30 8 * * * $1/group_mail.sh" >> /var/spool/cron/crontabs/root
}
# 开始执行
while [ 1 ]
do
if [ 1 ];then
echo -e "\033[32m ########################### String ########################### \033[0m"
# 功能选择
format_check
# 余额查询
banles=`dfx wallet --network ic balance | awk -F' ' '{print $1}'`
# 路径获取
dir=`pwd`
if [[ "$oper1" == "0" ]];then
read -p "Please enter the path of the configuration file:" mailConf
if [[ "$LINUX_OS" == "Ubuntu" ]];then
installMailboxDependenciesUbuntu
configureMailbox
elif [[ "$LINUX_OS" == "Centos" ]];then
echo "centos"
else
echo -e "\033[31m Error:Your system doesn't match! {OS: Ubuntu or Centos} \033[0m"
exit
fi
elif [[ "$oper1" == "1" ]];then
read -p "Please enter the path of the configuration file:" mailConf
onlySendMailTest $mailConf $banles $dir
elif [[ "$oper1" == "2" ]];then
sed -i "s/^.*banles.*$/banles=$banles/" $dir/balance.conf
onlySendMailSet $dir $banles
elif [[ "$oper1" == "3" ]];then
read -p "Please enter the path of the configuration file:" mailConf
groupSendMailTest $mailConf $banles $dir
elif [[ "$oper1" == "4" ]];then
read -p "Please enter the path of the configuration file:" mailConf
`sed -i "s/^.*banles.*$/banles=$banles/" $dir/balance.conf`
groupSendMailSet $dir
echo -e "\033[36m It will be reminded at 8:30 every day \033[0m"
else
exit
fi
fi
service cron restart
echo -e "\033[32m ########################### Stop ########################### \033[0m"
echo ""
done