iRedMail

iRedMail Install

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
mkdir /root/MyData/iredmail
cd /root/MyData/iredmail
touch iredmail-docker.conf

echo HOSTNAME=mail.aaa.com >> iredmail-docker.conf
echo FIRST_MAIL_DOMAIN=aaa.com >> iredmail-docker.conf
echo FIRST_MAIL_DOMAIN_ADMIN_PASSWORD=DFg234DSF@#rqw34fgsad >> iredmail-docker.conf
echo MLMMJADMIN_API_TOKEN=$(openssl rand -base64 32) >> iredmail-docker.conf
echo ROUNDCUBE_DES_KEY=$(openssl rand -base64 24) >> iredmail-docker.conf
echo MYSQL_ROOT_PASSWORD=BAThtp2HMR62uC >> iredmail-docker.conf

cd /root/MyData/iredmail
mkdir -p data/{backup,clamav,custom,imapsieve_copy,mailboxes,mlmmj,mlmmj-archive,mysql,sa_rules,ssl,postfix_queue}

docker run -d \
--name iredmail \
--env-file iredmail-docker.conf \
--hostname mail.aaa.com \
-p 84:80 \
-p 444:443 \
-p 25:25 \
-p 110:110 \
-p 995:995 \
-p 143:143 \
-p 993:993 \
-p 465:465 \
-p 587:587 \
-v /etc/letsencrypt:/etc/letsencrypt \
-v /root/MyData/iredmail/data/backup:/var/vmail/backup \
-v /root/MyData/iredmail/data/mailboxes:/var/vmail/vmail1 \
-v /root/MyData/iredmail/data/mlmmj:/var/vmail/mlmmj \
-v /root/MyData/iredmail/data/mlmmj-archive:/var/vmail/mlmmj-archive \
-v /root/MyData/iredmail/data/imapsieve_copy:/var/vmail/imapsieve_copy \
-v /root/MyData/iredmail/data/custom:/opt/iredmail/custom \
-v /root/MyData/iredmail/data/ssl:/opt/iredmail/ssl \
-v /root/MyData/iredmail/data/mysql:/var/lib/mysql \
-v /root/MyData/iredmail/data/clamav:/var/lib/clamav \
-v /root/MyData/iredmail/data/sa_rules:/var/lib/spamassassin \
-v /root/MyData/iredmail/data/postfix_queue:/var/spool/postfix \
iredmail/mariadb:stable

create_mail_user_SQL.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
#!/usr/bin/env bash

# Author: Zhang Huangbin (zhb _at_ iredmail.org)
# Purpose: Import users to SQL database from plain text file.
# Project: iRedMail (http://www.iredmail.org/)

# -------------------------------------------------------------------
# Usage:
# * Edit these variables:
# STORAGE_BASE_DIRECTORY
# DEFAULT_QUOTA='1024' # 1024 is 1GB
#
# * Run this script to generate SQL command used to create new user.
#
# bash create_mail_user_SQL.sh <new-email> <plain-password>iRedMail
#
# For example:
#
# bash create_mail_user_SQL.sh user@domain.ltd plain_password
#
# It will print SQL commands on console directly, you can redirect the
# output to a file for further use like this:
#
# bash create_mail_user_SQL.sh user@domain.ltd plain_password > output.sql
#
# * Import output.sql into SQL database like below:
#
# # mysql -uroot -p
# mysql> USE vmail;
# mysql> SOURCE /path/to/output.sql;
#
# # psql -d vmail
# sql> \i /path/to/output.sql;

# --------- CHANGE THESE VALUES ----------
# Storage base directory used to store users' mail.
STORAGE_BASE_DIRECTORY="/var/vmail/vmail1"

###########
# Password
#
# Password scheme. Available schemes: BCRYPT, SSHA512, SSHA, PLAIN.
# Check file Available
PASSWORD_SCHEME='SSHA512'

# Default mail quota (in MB).
DEFAULT_QUOTA='1024'

#
# Maildir settings
#
# Maildir style: hashed, normal.
# Hashed maildir style, so that there won't be many large directories
# in your mail storage file system. Better performance in large scale
# deployment.
# Format: e.g. username@domain.td
# hashed -> domain.ltd/u/us/use/username/
# normal -> domain.ltd/username/
# Default hash level is 3.
MAILDIR_STYLE='hashed' # hashed, normal.

if [ X"$#" != X'2' ]; then
echo "Invalid command arguments. Usage:"
echo "bash create_mail_user_SQL.sh user@domain.ltd plain_password"
exit 255
fi

# Time stamp, will be appended in maildir.
DATE="$(date +%Y.%m.%d.%H.%M.%S)"
WC_L='wc -L'
if [ X"$(uname -s)" == X'OpenBSD' ]; then
WC_L='wc -l'
fi

STORAGE_BASE="$(dirname ${STORAGE_BASE_DIRECTORY})"
STORAGE_NODE="$(basename ${STORAGE_BASE_DIRECTORY})"

generate_password_hash()
{
# Usage: generate_password_hash <password-scheme> <plain-password>
_scheme="${1}"
_password="${2}"

if [ X"${_scheme}" == X'BCRYPT' ]; then
_scheme='BLF-CRYPT'
fi

doveadm pw -s "${_scheme}" -p "${_password}"
}

# Read input
mail="$1"
plain_password="$2"

username="$(echo $mail | awk -F'@' '{print $1}')"
domain="$(echo $mail | awk -F'@' '{print $2}')"

# Cyrpt default password.
export CRYPT_PASSWD="$(generate_password_hash ${PASSWORD_SCHEME} ${plain_password})"

# Different maildir style: hashed, normal.
if [ X"${MAILDIR_STYLE}" == X"hashed" ]; then
length="$(echo ${username} | ${WC_L} )"
str1="$(echo ${username} | cut -c1)"
str2="$(echo ${username} | cut -c2)"
str3="$(echo ${username} | cut -c3)"

test -z "${str2}" && str2="${str1}"
test -z "${str3}" && str3="${str2}"

# Use mbox, will be changed later.
maildir="${domain}/${str1}/${str2}/${str3}/${username}-${DATE}/"
else
maildir="${domain}/${username}-${DATE}/"
fi

cat <<EOF
INSERT INTO mailbox (username, password, name,
storagebasedirectory,storagenode, maildir,
quota, domain, active, passwordlastchange, created)
VALUES ('${mail}', '${CRYPT_PASSWD}', '${username}',
'${STORAGE_BASE}','${STORAGE_NODE}', '${maildir}',
'${DEFAULT_QUOTA}', '${domain}', '1', NOW(), NOW());
INSERT INTO forwardings (address, forwarding, domain, dest_domain, is_forwarding)
VALUES ('${mail}', '${mail}','${domain}', '${domain}', 1);
EOF

create_mail_user

1
2
3
4
5
6
7
cd /opt/iredmail
bash create_mail_user_SQL.sh admin@aaa.com 'password' > user.sql


mysql -uroot -p
sql> USE vmail;
sql> SOURCE user.sql;
文章作者: Barry
文章链接: http://blog.purplelin.com/2021/05/14/IreadMail/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Barry