-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostfix.sh
212 lines (176 loc) · 7.05 KB
/
postfix.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
#!/bin/bash
# PostFix Auto Installer
# Created by Teguh Aprianto
# https://bukancoder | https://teguh.co
IJO='\e[38;5;82m'
MAG='\e[35m'
RESET='\e[0m'
echo -e "$IJO $RESET"
echo -e "$IJO __________ __ $MAG _________ .___ $RESET"
echo -e "$IJO \______ \__ __| | _______ ____ $MAG \_ ___ \ ____ __| _/___________ $RESET"
echo -e "$IJO | | _/ | \ |/ /\__ \ / \ $MAG / \ \/ / _ \ / __ |/ __ \_ __ \ $RESET"
echo -e "$IJO | | \ | / < / __ \| | \ $MAG \ \___( <_> ) /_/ \ ___/| | \/ $RESET"
echo -e "$IJO |______ /____/|__|_ \(____ /___| / $MAG \______ /\____/\____ |\___ >__| $RESET"
echo -e "$IJO \/ \/ \/ \/ $MAG \/ \/ \/ $RESET"
echo -e "$IJO --------------------------------------------------------------------------- $RESET"
echo -e "$IJO |$MAG PostFix Auto Installer $IJO| $RESET"
echo -e "$IJO --------------------------------------------------------------------------- $RESET"
echo -e "$IJO |$IJO Created by $IJO| $RESET"
echo -e "$IJO |$MAG Teguh Aprianto $IJO| $RESET"
echo -e "$IJO --------------------------------------------------------------------------- $RESET"
echo ""
echo -e "$MAG--=[ To start install PostFix and Cyrus, press any key to continue ]=--$RESET"
read answer
echo -e "$MAG--=[ Adding domain for mail server ]=--$IJO"
domain="yourdomain.com"
read -p "Domain for email : " domain
if [ "$domain" = "" ]; then
domain="yourdomain.com"
fi
echo "---------------------------"
echo "Domain : $domain"
echo "---------------------------"
echo
echo
echo -e "$MAG--=[ Username for email ]=--$IJO"
username="bukancoder"
read -p "Domain for email : " username
if [ "$username" = "" ]; then
username="bukancoder.com"
fi
echo "---------------------------"
echo "Email : $username@$domain"
echo "---------------------------"
echo
echo
echo -e "$MAG--=[ Installing PostFix and Cyrus ]=--$IJO"
yum -y install postfix
yum -y install cyrus-sasl
yum -y install cyrus-imapd
echo
echo
echo -e "$MAG--=[ Config PostFix for domain $IJO $domain $MAG]=--$IJO"
rm -rf /etc/postfix/main.cf
myhostname='$myhostname'
cat >/etc/postfix/main.cf<<eof
$alf
soft_bounce = no
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
mail_owner = postfix
# The default_privs parameter specifies the default rights used by
# the local delivery agent for delivery to external file or command.
# These rights are used in the absence of a recipient user context.
# DO NOT SPECIFY A PRIVILEGED USER OR THE POSTFIX OWNER.
#
#default_privs = nobody
myhostname = $domain
mydomain = $domain
mydestination = $myhostname, localhost
unknown_local_recipient_reject_code = 550
mynetworks_style = host
mailbox_transport = lmtp:unix:/var/lib/imap/socket/lmtp
local_destination_recipient_limit = 300
local_destination_concurrency_limit = 5
recipient_delimiter=+
virtual_alias_maps = hash:/etc/postfix/virtual
header_checks = regexp:/etc/postfix/header_checks
mime_header_checks = pcre:/etc/postfix/body_checks
smtpd_banner = $myhostname
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/bin:/usr/X11R6/bin
xxgdb $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.3.3/samples
readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES
smtpd_sasl_auth_enable = yes
smtpd_sasl_application_name = smtpd
smtpd_recipient_restrictions = permit_sasl_authenticated,
permit_mynetworks,
reject_unauth_destination,
reject_invalid_hostname,
reject_non_fqdn_hostname,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unknown_sender_domain,
reject_unknown_recipient_domain,
reject_unauth_pipelining,
reject_rbl_client zen.spamhaus.org,
reject_rbl_client bl.spamcop.net,
reject_rbl_client dnsbl.njabl.org,
reject_rbl_client dnsbl.sorbs.net,
permit
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain =
broken_sasl_auth_clients = yes
smtpd_helo_required = yes
eof
echo
echo
echo -e "$MAG--=[ Configure virtual PostFix for domain $IJO $domain $MAG ]=--$IJO"
rm -rf /etc/postfix/virtual
cat >/etc/postfix/virtual<<eof
$alf
$username@$domain $username\@$domain
eof
postmap /etc/postfix/virtual
touch /etc/postfix/body_checks
echo
echo
echo -e "$MAG--=[ Configure Cyrus ]=--$IJO"
rm -rf /etc/sasl2/smtpd.conf
cat >/etc/sasl2/smtpd.conf<<eof
$alf
pwcheck_method: auxprop
auxprop_plugin: sasldb
mech_list: PLAIN LOGIN CRAM-MD5 DIGEST-MD5
eof
echo
echo
echo -e "$MAG--=[ Configure the Cyrus file ]=--$IJO"
rm -rf /etc/imapd.conf
cat >/etc/imapd.conf<<eof
$alf
virtdomains: userid
defaultdomain: $domain
servername: $domain
configdirectory: /var/lib/imap
partition-default: /var/spool/imap
admins: cyrus
sievedir: /var/lib/imap/sieve
sendmail: /usr/sbin/sendmail.postfix
hashimapspool: true
allowanonymouslogin: no
allowplaintext: yes
sasl_pwcheck_method: auxprop
sasl_mech_list: CRAM-MD5 DIGEST-MD5 PLAIN
tls_cert_file: /etc/pki/cyrus-imapd/cyrus-imapd.pem
tls_key_file: /etc/pki/cyrus-imapd/cyrus-imapd.pem
tls_ca_file: /etc/pki/tls/certs/ca-bundle.crt
autocreatequota: -1
createonpost: yes
autocreateinboxfolders: spam
autosubscribeinboxfolders: spam
eof
echo
echo
echo -e "$MAG--=[ Install Mail Client ]=--$IJO"
yum -y install mailx
echo
echo
echo -e "$MAG--=[ Test to send email ]=--$IJO"
read -p "Test send email to? Paste your email : " email
echo "---------------------------"
echo "Email : $email"
echo "---------------------------"
mail -s "Test Send Email" $email <<< "Just test bro"
echo -e "$MAG Test email has been sent to email $IJO $email $MAG please check your inbox or your spam folder $IJO"
echo
echo -e "$MAG--=[Done! Postfix for domain $IJO http://$domain $MAG has been installed on your server $MAG]=--$IJO"