-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpostfix_dovecot
executable file
·220 lines (178 loc) · 5.29 KB
/
postfix_dovecot
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
#!/bin/bash
#################################################
# Install script for Mail server
# Setting for virtual accounts and domains.
#
# This script was tested with Ubuntu 10.04 TLS.
#
# Required:
#
# Author : Takahiro Fujiwara ( tfmagician )
# Created : 2010-12-05
# Updated : 2011-01-24
#################################################
# Check executable user.
if [ "`whoami`" != "root" ]; then
echo "You need to be root to run this!"
exit 2
fi
##
echo 'Install Postfix and Dovecot'
apt-get install -y postfix postfix-dev dovecot-common dovecot-dev dovecot-imapd dovecot-pop3d dovecot-postfix mailutils
##
echo 'Add user to controll virtual users of mail server'
useradd -u 5000 -m -d /var/vmail vmail
##
echo 'Create virtual users.'
while [ -z "${DOMAIN}" ]; do
echo -n 'Enter virtual domain: '
read DOMAIN
done
while [ -z "${ACCOUNTS}" ]; do
echo -n 'Enter virtual user accounts ( if you have some users, split spaces ): '
read ACCOUNTS
done
while [ -z "${SUPPORT}" ]; do
echo -n "Select support account ( ${ACCOUNTS} ): "
read SUPPORT
done
cat > /etc/postfix/main.cf <<CONF
###############################################################
# Basic settings
###############################################################
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
mail_owner = postfix
# Postfix receive mails from this interfaces.
inet_interfaces = all
# Trust SMTP clients.
mynetworks = 127.0.0.1
# MTA hostname.
myhostname = ${DOMAIN}
# If this server sends email containing only username, postfix appends myorigin to username.
append_at_myorigin = yes
myorigin = `hostname`.localdomain
# Comment out because of using virtual host.
#mydomain = localhost
# Postfix only receives email by these domains.
mydestination = `hostname`.localdomain, localhost.localdomain, localhost
unknown_local_recipient_reject_code = 550
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
###############################################################
# Virtual mailbox settings
###############################################################
virtual_mailbox_domains = /etc/postfix/virtual-conf/domains
virtual_mailbox_base = /var/vmail
virtual_mailbox_maps = hash:/etc/postfix/virtual-conf/mailboxes
virtual_minimum_uid = 5000
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
###############################################################
# SMTP Auth
###############################################################
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions =
permit_mynetworks
permit_sasl_authenticated
reject_unauth_destination
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/dovecot-auth
###############################################################
# TLS
###############################################################
smtpd_use_tls = yes
smtpd_tls_cert_file = /etc/ssl/certs/ssl-mail.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-mail.key
smtp_tls_CApath = /etc/ssl/certs/ca-certificates.crt
smtpd_tls_loglevel = 1
###############################################################
# Relay Gmail server
###############################################################
#relayhost = [smtp.gmail.com]:587
#smtp_use_tls = yes
#smtp_sasl_auth_enable = yes
#smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
#smtp_sasl_tls_security_options = noanonymous
#smtp_sasl_mechanism_filter = plain
###############################################################
# Others
###############################################################
# For debug.
#debug_peer_level = 2
#debugger_command =
# PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
# xxgdb \$daemon_directory/\$process_name \$process_id & sleep 5
# Some command paths.
sendmail_path = /usr/sbin/sendmail
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
setgid_group = postdrop
# For documents.
#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
CONF
if [ ! -e /etc/postfix/virtual-conf ]; then
mkdir /etc/postfix/virtual-conf
fi
cat > /etc/postfix/virtual-conf/domains <<CONF
${DOMAIN}
CONF
for ACCOUNT in ${ACCOUNTS}; do
cat >> /etc/postfix/virtual-conf/mailboxes <<CONF
${ACCOUNT}@${DOMAIN} ${DOMAIN}/${ACCOUNT}/
CONF
done
postmap /etc/postfix/virtual-conf/mailboxes
newaliases
/etc/init.d/postfix restart
cp /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.org
cat > /etc/dovecot/dovecot.conf <<CONF
protocols = imap pop3
listen = *
disable_plaintext_auth = no
ssl = no
mail_location = maildir:/var/vmail/%d/%n
protocol imap {
}
protocol pop3 {
}
protocol lda {
postmaster_address = ${SUPPORT}@${DOMAIN}
}
auth default {
mechanisms = cram-md5 plain
user = root
passdb passwd-file {
args = /etc/dovecot/passwd
}
userdb passwd-file {
args = /etc/dovecot/passwd
}
socket listen {
client {
path = /var/spool/postfix/private/dovecot-auth
mode = 0660
user = postfix
group = postfix
}
}
}
dict {
}
plugin {
}
CONF
for ACCOUNT in ${ACCOUNTS}; do
echo "Enter password for user ${ACCOUNT}"
while [ -z "${PASSWORD}" ]; do
PASSWORD=`dovecotpw -s CRAM-MD5`
done
cat >> /etc/dovecot/passwd <<CONF
${ACCOUNT}@${DOMAIN}:${PASSWORD}:5000:5000
CONF
unset PASSWORD
done
/etc/init.d/dovecot restart