-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathmail_install.sh
743 lines (682 loc) · 27.5 KB
/
mail_install.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
#!/bin/bash
# 前言
# 为什么要自己搭邮服发信
# 第一,灵活方便,随用随搭,一旦上了有价值的目标之后就立即销毁,相对目标自身的实际价值来讲,这个成本并不算非常高,只有在用的时候才把邮件服务开起来,不用的时候就关掉
# 第二,全程可控,用各种第三方邮服去代发的问题就在于你根本不知道别人到底在后端做了啥(但你做了啥,别人却看的一清二楚),当然,不仅仅只是这一个方面
# 第三,把这个再稍微延申扩展下,比如,写个漂亮的GUI套上,转身一变其实就是个很好的开源钓鱼平台
# 等等等等等等....不再赘述
# 大致部署过程如下
# 首先,去申请一个近似域名(即跟目标相似度最高的域名,不建议用伪造,通常都会直接被各种邮件网关拦掉),然后再到域名里去添加好如下记录
# 一条名为mail的A记录,指向 vpsip
# 一条MX记录 @ ,指向 mail.yourdomain.com,优先级1
# 一条名为smtp的CNAME记录,指向mail.yourdomain.com
# 一条名为pop3的CNAME记录,指向mail.yourdomain.com
# 一条名为imap的CNAME记录,指向mail.yourdomain.com
# 一条txt记录, @ 值为 v=spf1 a mx -all
# 接着,去自己的VPS上执行一些初始操作
# passwd # 改密码
# echo "mail.yourdomain.com" > /etc/hostname # 修改机器名
# echo yourvpsip mail.yourdomain.com >> /etc/hosts # 修改解析
# shutdown -r now # 最后,重启系统使之生效
# 之后,等上大概个半小时左右(其实可能要不了这么久),主要是为了等域名解析记录生效,之后再开始执行该脚本
# 详细确认您的VPS厂商是否允许所有邮件服务端口正常通信(安全组是否已放开相关邮件服务端口)
# 很多厂商为了避免vps被用来滥发垃圾邮件而导致ip被标记,默认会直接禁掉25端口通信
# 最后,再仔细确认下自己的VPS IP和域名曾经是否进过各种黑名单,比如,曾经被人用来做过C2,RAT域名,发过垃圾邮件 等等等...这些问题后续都会严重影响邮件的实际送达率
# 脚本最终部署的环境,包括 Certbot + Postfix + Dovecot + Opendkim ...
# 时间仓促,脚本写的并不是很精细,有空的话,可以把所有的前期检测及服务起停动作都可以写成函数进行调用,方便一些
if [ $# -eq 0 ] || [ $# != 3 ] ;then
echo -e "\n#####################################################################################"
echo "# #"
echo "# 发信平台一键部署脚本 (Tested on Ubuntu 16.04 LTS 64bit) #"
echo "# #"
echo "# Author: klion #"
echo "# 2020.5.8 #"
echo "# #"
echo "#####################################################################################"
echo "# #"
echo "# Usage: #"
echo "# /root/MailSrv_Autoinstall.sh 你的VPSIP 你的域名 接收测试邮件的邮箱(随意) #"
echo "# /root/MailSrv_Autoinstall.sh \"13.29.117.68\" \"happy.com\" \"[email protected]\" #"
echo "# #"
echo -e "#####################################################################################\n"
exit
fi
vpsip=$1
yourdomain=$2
yourmail=$3
# 判断当前用户权限
if [ `id -u` -ne 0 ];then
echo -e "\n\033[33m请以 root 权限 运行该脚本! \033[0m\n"
exit
fi
# 安装基础工具及相关依赖
ping github.com -c 5 >/dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "\n\e[92m请仔细确认域名的相关解析记录都已事先添加好且可正常解析 ! \e[0m"
sleep 3
echo -e "\e[94m网络正常,开始安装基础工具及相关依赖,请稍后...\e[0m"
sleep 3
apt-get update >/dev/null 2>&1
apt-get install gcc gdb make cmake socat telnet tree tcpdump iptraf iftop nethogs lrzsz git unzip curl wget vim python2.7 python2.7-dev -y >/dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "\e[94m相关工具及依赖库已全部安装成功,准备安装 Postfix,请稍后...\e[0m\n"
sleep 3
else
echo -e "工具安装失败,请检查后重试!"
exit
fi
else
echo -e "网络连接似乎有问题,请检查后重试!"
exit
fi
echo -e "=========================================================================\n"
# 安装配置nc
which "add-apt-repository" > /dev/null
if [ $? -eq 0 ];then
add-apt-repository universe >/dev/null 2>&1
if [ $? -eq 0 ];then
apt-get install netcat-traditional -y >/dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "\e[94mNc 安装成功 ! \e[0m"
update-alternatives --set nc /bin/nc.traditional >/dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "\e[94mNc 配置成功 ! \e[0m\n"
sleep 1
else
echo -e "Nc 配置失败,请检查后重试!"
exit
fi
else
echo -e "Nc 安装失败,请检查后重试!"
exit
fi
else
echo -e "PPA 添加失败,请检查后重试!"
exit
fi
else
echo -e "add-apt-repository 命令不存在,请尝试安装后重试!"
exit
fi
# 判断当前系统中是否有占用邮件服务端口的进程
arr=(25 110 143 465 587 993 995 8891)
for(( i=0;i<${#arr[@]};i++))
do
nc -z -v -w 2 127.0.0.1 ${arr[i]} >/dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "${arr[i]} 端口被占用,请kill掉相关进程后重试!"
exit
fi
done;
# 检查当前系统之前是否已安装过邮件服务
if [ -d "/etc/postfix/" ] ; then
echo -e "Postfix 已安装,为尽可能避免后续出问题,请尝试卸载后再重新安装!"
exit
if [ -d "/etc/dovecot/" ] ;then
echo -e "Dovecot 已安装,为尽可能避免后续出问题,请尝试卸载后再重新安装!"
exit
if [ -d "/etc/letsencrypt/" ] ;then
echo -e "Certbot 可能已经安装过,为尽可能避免后续出问题,请尝试删除证书目录后再重新申请!"
exit
fi
fi
fi
echo -e "=========================================================================\n"
# 安装postfix
which "debconf-set-selections" > /dev/null
if [ $? -eq 0 ];then
echo -e "\e[94m开始安装Postfix,请稍后...\e[0m"
debconf-set-selections <<< "postfix postfix/mailname string mail.${yourdomain}"
debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"
if [ $? -eq 0 ];then
apt-get install --assume-yes postfix -y >/dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "\e[94mPostfix安装成功,准备安装Certbot,请稍后...\e[0m\n"
sleep 3
else
echo -e "Postfix安装失败,请检查后重试..."
exit
fi
else
echo -e "Debconf Set 失败,请检查后重试..."
exit
fi
else
echo -e "Debconf 不存在,请手工安装后重试..."
exit
fi
echo -e "=========================================================================\n"
# 安装certbot,申请免费证书,此处务必要注意,同一个域名不能申请次数太多,貌似三次就不给了
apt-get install certbot -y >/dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "\e[94mCertbot安装成功,准备申请证书\e[0m"
certbot certonly --non-interactive --standalone -d mail.${yourdomain} --agree-tos -m [email protected] >/dev/null 2>&1
if [ $? -eq 0 ] && [ -d "/etc/letsencrypt/live/mail.${yourdomain}/" ]; then
echo -e "\e[94m证书申请成功,开始配置Postfix, 请稍后...\e[0m\n"
else
echo -e "证书申请失败,请检查后重试..."
exit
fi
else
echo -e "Certbot安装失败,请检查后重试..."
exit
fi
echo -e "=========================================================================\n"
# 配置 Postfix
cat << EOF > /etc/postfix/main.cf
myhostname = mail.${yourdomain}
myorigin = $mydomain
mydomain = ${yourdomain}
mydestination = $mydomain, $myhostname, mail.${yourdomain}, localhost.${yourdomain}, , localhost
smtpd_banner = $myhostname ESMTP $mail_name (TmpSrv)
home_mailbox = Maildir/
mynetworks = 0.0.0.0 ${vpsip} 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
biff = no
append_dot_mydomain = no
readme_directory = no
smtpd_tls_cert_file=/etc/letsencrypt/live/mail.${yourdomain}/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/mail.${yourdomain}/privkey.pem
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_local_domain =
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtp_tls_security_level = may
smtpd_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_milters = inet:127.0.0.1:8891
non_smtpd_milters = inet:127.0.0.1:8891
milter_protocol = 2
milter_default_action = accept
disable_vrfy_command = yes
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mail.${yourdomain}
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
relayhost =
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
EOF
if [ $? -eq 0 ];then
echo -e "\e[94m/etc/postfix/main.cf 配置修改成功 ! \e[0m"
sleep 2
else
echo -e "/etc/postfix/main.cf 配置修改失败,请检查后重试... !"
exit
fi
cat << EOF > /etc/postfix/master.cf
smtp inet n - y - - smtpd
submission inet n - y - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
-o milter_macro_daemon_name=ORIGINATING
smtps inet n - y - - smtpd
-o syslog_name=postfix/smtps
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
-o milter_macro_daemon_name=ORIGINATING
pickup unix n - y 60 1 pickup
cleanup unix n - y - 0 cleanup
qmgr unix n - n 300 1 qmgr
tlsmgr unix - - y 1000? 1 tlsmgr
rewrite unix - - y - - trivial-rewrite
bounce unix - - y - 0 bounce
defer unix - - y - 0 bounce
trace unix - - y - 0 bounce
verify unix - - y - 1 verify
flush unix n - y 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - y - - smtp
relay unix - - y - - smtp
showq unix n - y - - showq
error unix - - y - - error
retry unix - - y - - error
discard unix - - y - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - y - - lmtp
anvil unix - - y - 1 anvil
scache unix - - y - 1 scache
maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
uucp unix - n n - - pipe
flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
ifmail unix - n n - - pipe
flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp unix - n n - - pipe
flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix - n n - 2 pipe
flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman unix - n n - - pipe
flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
${nexthop} ${user}
EOF
if [ $? -eq 0 ];then
echo -e "\e[94m/etc/postfix/master.cf 配置修改成功, 准备安装Dovecot, 请稍后...\e[0m\n"
sleep 2
else
echo -e "/etc/postfix/master.cf 配置修改失败,请检查后重试...!\n"
exit
fi
echo -e "=========================================================================\n"
# 安装 Dovecot
apt-get install dovecot-core dovecot-imapd dovecot-pop3d -y >/dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "\e[94mDovecot安装成功,准备配置Dovecot,请稍后...\e[0m"
sleep 2
else
echo -e "Dovecot安装失败,请检查后重试..."
exit
fi
cat << EOF > /etc/dovecot/conf.d/10-master.conf
service imap-login {
inet_listener imap {
}
inet_listener imaps {
}
}
service pop3-login {
inet_listener pop3 {
}
inet_listener pop3s {
}
}
service lmtp {
unix_listener lmtp {
}
}
service imap {
}
service pop3 {
}
service auth {
unix_listener auth-userdb {
}
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
}
service auth-worker {
}
service dict {
unix_listener dict {
}
}
EOF
if [ $? -eq 0 ];then
echo -e "\e[94m/etc/dovecot/conf.d/10-master.conf 配置修改成功 ! \e[0m"
sleep 2
else
echo -e "/etc/dovecot/conf.d/10-master.conf 配置修改失败,请检查后重试!"
exit
fi
cat << EOF > /etc/dovecot/conf.d/10-auth.conf
auth_mechanisms = plain login
!include auth-system.conf.ext
# egrep -v '^$|#' /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir
namespace inbox {
inbox = yes
}
EOF
if [ $? -eq 0 ];then
echo -e "\e[94m/etc/dovecot/conf.d/10-auth.conf 配置修改成功 ! \e[0m"
sleep 2
else
echo -e "/etc/dovecot/conf.d/10-auth.conf 配置修改失败,请检查后重试!"
exit
fi
cat << EOF > /etc/dovecot/conf.d/20-pop3.conf
pop3_uidl_format = %08Xu%08Xv
protocol pop3 {
}
EOF
if [ $? -eq 0 ];then
echo -e "\e[94m/etc/dovecot/conf.d/20-pop3.conf 配置修改成功 ! \e[0m"
sleep 2
else
echo -e "/etc/dovecot/conf.d/20-pop3.conf 配置修改失败,请检查后重试!"
exit
fi
cat << EOF > /etc/dovecot/conf.d/10-ssl.conf
ssl = yes
ssl_cert = </etc/letsencrypt/live/mail.${yourdomain}/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.${yourdomain}/privkey.pem
EOF
if [ $? -eq 0 ];then
echo -e "\e[94m/etc/dovecot/conf.d/10-ssl.conf 配置修改成功 ! \e[0m\n"
sleep 2
else
echo -e "/etc/dovecot/conf.d/10-ssl.conf 配置修改失败,请检查后重试!"
exit
fi
echo -e "=========================================================================\n"
# 安装 Opendkim
apt-get install opendkim opendkim-tools -y >/dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "\e[94mOpendkim 安装成功 ! \e[0m"
sleep 2
else
echo -e "Opendkim 安装失败,请检查后重试!"
exit
fi
mkdir -p /var/run/opendkim
if [ -d "/var/run/opendkim/" ]; then
echo -e "\e[94m/var/run/opendkim/ 目录创建成功 ! \e[0m"
sleep 2
mkdir /etc/opendkim
if [ -d "/etc/opendkim" ]; then
echo -e "\e[94m/etc/opendkim 目录创建成功! 准备配置Opendkim ,请稍后...\e[0m"
chown -R opendkim:opendkim /var/run/opendkim
sleep 2
else
echo -e "/etc/opendkim 目录创建失败,请检查后重试!"
exit
fi
else
echo -e "/var/run/opendkim/ 目录创建失败,请检查后重试!"
exit
fi
cat << EOF > /etc/opendkim.conf
Syslog yes
UMask 002
Domain ${yourdomain}
Canonicalization relaxed/relaxed
Mode sv
OversignHeaders From
TrustAnchorFile /usr/share/dns/root.key
ExternalIgnoreList refile:/etc/opendkim/TrustedHosts
InternalHosts refile:/etc/opendkim/TrustedHosts
KeyTable refile:/etc/opendkim/KeyTable
LogWhy Yes
PidFile /var/run/opendkim/opendkim.pid
SigningTable refile:/etc/opendkim/SigningTable
Socket inet:[email protected]
SyslogSuccess Yes
TemporaryDirectory /var/tmp
UserID opendkim:opendkim
EOF
if [ $? -eq 0 ];then
echo -e "\e[94m/etc/opendkim.conf 配置修改成功 ! \e[0m"
sleep 2
else
echo -e "/etc/opendkim.conf 配置修改失败,请检查后重试!"
exit
fi
mkdir /etc/opendkim/keys/${yourdomain} -p
if [ -d "/etc/opendkim/keys/${yourdomain}" ]; then
echo -e "\e[94m/etc/opendkim/keys/${yourdomain} 目录创建成功 ! \e[0m"
sleep 2
else
echo -e "/etc/opendkim/keys/${yourdomain} 目录创建失败! 请检查后重试!"
exit
fi
opendkim-genkey -D /etc/opendkim/keys/${yourdomain}/ -d ${yourdomain} -s default
if [ $? -eq 0 ];then
echo -e "\e[94mopendkim-genkey 生成成功! \e[0m"
echo "default._domainkey.${yourdomain} ${yourdomain}:default:/etc/opendkim/keys/${yourdomain}/default.private" > /etc/opendkim/KeyTable
echo "*@${yourdomain} default._domainkey.${yourdomain}" > /etc/opendkim/SigningTable
echo "127.0.0.1" > /etc/opendkim/TrustedHosts
sleep 2
else
echo -e "opendkim-genkey 生成失败, 请检查后重试!"
fi
cat << EOF > /etc/default/opendkim
SOCKET="local:/var/run/opendkim/opendkim.sock"
SOCKET="inet:[email protected]"
EOF
if [ $? -eq 0 ];then
echo -e "\e[94m/etc/default/opendkim 配置修改成功 ! \e[0m\n"
chown -R opendkim:opendkim /etc/opendkim/keys/${yourdomain}
sleep 2
else
echo -e "/etc/default/opendkim 配置修改失败,请检查后重试!"
exit
fi
echo -e "=========================================================================\n"
# 启动邮件服务
systemctl restart postfix.service
if [ $? -eq 0 ];then
echo -e "\e[94mPostfix 服务启动成功 ! \e[0m"
sleep 3
systemctl restart dovecot.service
if [ $? -eq 0 ];then
echo -e "\e[94mDovecot 服务启动成功 ! \e[0m"
sleep 3
systemctl restart opendkim.service
if [ $? -eq 0 ];then
echo -e "\e[94mOpendkim 服务启动成功 ! \e[0m\n"
sleep 3
else
echo -e "Opendkim 服务启动失败! 请检查后重试...!"
exit
fi
else
echo -e "Dovecot 服务启动失败! 请检查后重试...!"
exit
fi
else
echo -e "Postfix 服务启动失败! 请检查后重试...!"
exit
fi
echo -e "=========================================================================\n"
# 握手测试
openssl s_client -showcerts -connect mail.${yourdomain}:465 <<< 'Q' >/dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "\e[94m465端口正常握手 ! \e[0m"
sleep 2
openssl s_client -showcerts -connect mail.${yourdomain}:993 <<< 'Q' >/dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "\e[94m993端口正常握手 ! \e[0m"
sleep 2
openssl s_client -showcerts -connect mail.${yourdomain}:995 <<< 'Q' >/dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "\e[94m995端口正常握手 ! \e[0m"
sleep 2
else
echo -e "995端口请求正常, 请检查后重试...!"
exit
fi
else
echo -e "993端口请求, 请检查后重试... !"
exit
fi
else
echo -e "465端口请求异常, 请检查后重试...!"
exit
fi
if [ -f "/var/log/mail.log" ]; then
echo -e "\e[94m邮件收发记录日志文件路径: /var/log/mail.log\e[0m\n"
sleep 2
else
echo -e "请从头一步步仔细排查所有安装配置选项,而后重试\n"
fi
echo -e "=========================================================================\n"
echo -e "请到自己的域名中添加一个名为 '\033[33m_dmarc\033[0m' 的txt记录,并将如下值写进入"
echo -e "\e[94mv=DMARC1;p=none;rua=mailto:admin@${yourdomain}\e[0m"
sleep 3 && echo
echo -e "请到自己的域名中添加一个名为 '\033[33mdefault._domainkey\033[0m' 的txt记录,之后将如下值写入,此处脚本将等待八分钟后执行,以预留出足够的时间去添加记录"
cat /etc/opendkim/keys/${yourdomain}/default.txt && echo
sleep 480
echo -e "=========================================================================\n"
# 添加邮箱用户
echo -e "\e[92m开始添加测试邮箱账户\e[0m\n"
id system >/dev/null 2>&1
if [ $? != 0 ];then
useradd -m system -s /sbin/nologin
echo -e "\e[94m邮箱账户system 添加成功 ! \e[0m"
sleep 2
id admin >/dev/null 2>&1
if [ $? != 0 ];then
useradd -m admin -s /sbin/nologin
echo -e "\e[94m邮箱账户admin 添加成功 ! \e[0m"
sleep 2
id manager >/dev/null 2>&1
if [ $? != 0 ];then
useradd -m manager -s /sbin/nologin
echo -e "\e[94m邮箱账户manager 添加成功 ! \e[0m\n"
sleep 2
else
echo -e "邮箱账户manager 添加失败!"
exit
fi
else
echo -e "邮箱账户admin 添加失败!"
exit
fi
else
echo -e "邮箱账户system 添加失败!"
exit
fi
echo -e "=========================================================================\n"
# 注意,实际中也不建议去伪造(较大几率被拦截),用近似域名会相对好很多,此处的邮件内容是随便写的,实际用的时候替换下即可
cat << EOF > mails.txt
helo client
MAIL FROM:<admin@${yourdomain}>
RCPT TO:<${yourmail}>
DATA
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_38945_682591813.1587958302122"
From: =?GBK?B?0MXPorCyyKuyvw==?= <admin@${yourdomain}>
To: ${yourmail} <${yourmail}>
Subject: =?GBK?B?ob7Ptc2z08q8/iC3x7Oj1tjSqqG/vfzG2g==?=
=?GBK?B?o6y5q8u+vOC/2M+1zbO3os/Wsr+31lZQTg==?=
=?GBK?B?1cu6xbTm1NrS7LOjstnX99DQzqqjrMfrvLA=?=
=?GBK?B?yrHW2NDCtcfCvNLUzeqzydXLusWwssir19S87A==?=
------=_Part_38945_682591813.1587958302122
Content-Type: text/plain; charset=GBK
Content-Transfer-Encoding: base64
x9ewrrXEzazKwsPHo6wKCgoKCr38xtqjrLmry7684L/Yz7XNs7K21721vcSz0KlWUE7Vy7rFtObU
2sr9tM7S7LOjstnX99DQzqqjrLj5vt3O0su+o6i8r83Fo6nN+MLnsLLIq7nmtqijrM6qyLexo9XL
usWwssiro6zP1tDo0qrL+dPQvt/T0FZQTrXHwrzIqM/etcTNrMrCxeS6z6Oozt5WUE61x8K8yKjP
3rXEzazKwr/J1rG907r2wtS0y9PKvP6jqaOsvqG/7NbY0MK1x8K8VlBOz7XNs9LUzeqzyVZQTtXL
usWwssirvOyy6aOsILXHwrxWUE7Ptc2zIGh0dHBzOi8vc3NsdnBuLm1pdHJlLm9yZyCjrLzssum5
/bPMvavIq7PM19S2r7340NCjrM7e0OjIy86quMnUpKOsvt/M5bLZ1/fI58/CzbzL+cq+o6zXoqOs
0+LG2s60vfjQ0LCyyKvX1LzstcRWUE7Vy7rFvavIq7K/sbvK1bvYu/LL+Laoo6zPtc2z08q8/qOs
x+vO8LvWuLQKCgoKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICDEs8SzuavLvqOov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9zcGFuPjwvZGl2Pjxicj48YnI+
PHNwYW4gdGl0bGU9Im5ldGVhc2Vmb290ZXIiPjxwPiZuYnNwOzwvcD48L3NwYW4+
------=_Part_38945_682591813.1587958302122--
.
quit
EOF
cat mails.txt | /bin/nc -vv mail.${yourdomain} 25 >/dev/null 2>&1
if [ $? -eq 0 ];then
# 如果收件箱找不到邮件,请到垃圾箱看看,一般前面配置没问题,域名/ip没进黑名单的情况下,几乎是不会进垃圾箱的
echo -e "\e[94m测试邮件已发送成功,请前往 ${yourmail} 邮箱收件箱查看 ! \e[0m"
echo -e "\e[94m恭喜! 至此,发信平台已全部部署完成 ! \e[0m\n"
else
echo -e "测试邮件发送失败,请从头逐步仔细核对您的所有邮件服务配置后重试 ! \n"
exit
fi
rm -fr mails.txt
# 一键停止所有邮件服务
# systemctl stop postfix.service
# if [ $? -eq 0 ];then
# echo -e "\e[94mPostfix 服务已停止 ! \e[0m"
# sleep 3
# systemctl stop dovecot.service
# if [ $? -eq 0 ];then
# echo -e "\e[94mDovecot 服务已停止! \e[0m"
# sleep 3
# systemctl stop opendkim.service
# if [ $? -eq 0 ];then
# echo -e "\e[94mOpendkim 服务已停止! \e[0m\n"
# sleep 3
# else
# echo -e "Opendkim 服务关闭失败! 请检查后重试...!"
# exit
# fi
# else
# echo -e "Dovecot 服务关闭失败! 请检查后重试...!"
# exit
# fi
# else
# echo -e "Postfix 服务关闭失败! 请检查后重试...!"
# exit
# fi
# 批量延迟发信
# while read -r line
# do
# sed -i 's/Targetmail/$line/g' mails.txt
# sed -i 's/Mydomain/${Mydomain}/g' mails.txt
# sleep 10
# cat mails.txt | /bin/nc -vv mail.${Mydomain} 25
# done < targetmails.txt