mail_server/README.txt

265 lines
8.2 KiB
Text
Raw Normal View History

2021-05-05 15:59:23 +00:00
# MAIL SERVER
2021-05-05 14:39:14 +00:00
#######################################################
Self Hosted Email Server with postfixadmin + roundcubemail + dovecot + postfix + spamassassin
#######################################################
# Following resources depends on your users count.
2021-05-05 16:07:40 +00:00
# Supports up to 200 users.
# Supports up to 20k mail flow daily mail flow handles.
RAM: 2 GiB
SWAP: 2x RAM
Disk: 20GB OR your requirement as per user count.
2021-05-05 14:39:14 +00:00
CPU: 2 or 4 core.
2021-05-05 16:27:58 +00:00
# Operating System and Components Version:
OS: Centos 7.x (Minimal Package)
2021-05-05 16:07:40 +00:00
Dovecot: 2.2.36
Postfix: 2.10.1
SpamAssassin: 3.4.0
PHP: 7.4.16
Postfixadmin: 3.3.8
Roundcubemail: 1.4.11
Apache: 2.4.6
2021-05-05 16:27:58 +00:00
Reference Link:
https://github.com/postfixadmin/postfixadmin
https://github.com/roundcube/roundcubemail
2021-05-05 14:39:14 +00:00
# Install required packages.
yum install -y epel-release yum-utils http://rpms.remirepo.net/enterprise/remi-release-7.rpm vim net-tools ; yum-config-manager --enable remi-php74 ; yum -y install postfix dovecot dovecot-mysql dovecot-pigeonhole mariadb-server telnet mailx wget ; yum -y install spamassassin ; yum install -y libopendkim opendkim; yum install -y postgrey spamassassin spamass-milter-postfix spamass-milter; yum install -y clamav-filesystem clamav-server clamav-update clamav-milter-systemd clamav-data clamav-server-systemd clamav-scanner-systemd clamav clamav-milter clamav-lib clamav-devel; yum install -y php php-cli php-gd php-xml php-curl php-mysql php-zip php-mbstring php-mcrypt php-fpm php-imap php-common php-pdo php-intl php-imagick; yum update -y; yum clean all;
# Enable and start mariadb service.
systemctl enable mariadb && systemctl start mariadb && systemctl status mariadb
# Disable selinux.
getenforce
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0
# Reboot server.
reboot
# Setup MySQL root password.
mysql_secure_installation
Configure it like this:
- Enter current password for root (enter for none): (Just Enter)
- Set root password? [Y/n] y
New password: <STRONGPASSWORD>
Re-enter new password: <STRONGPASSWORD>
Password updated successfully!
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y
2021-05-05 15:59:23 +00:00
# Create postfixadmin database and user.
2021-05-05 14:39:14 +00:00
mysql -u root -p;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'example#2345';
SELECT host, user FROM mysql.user;
CREATE DATABASE vmailadmin;
GRANT ALL PRIVILEGES ON vmailadmin.* TO 'vmailadmin'@'localhost' IDENTIFIED BY 'STRONGPASSWORD';
grant select on vmailadmin.* to 'vmailadmin'@'localhost' identified by 'STRONGPASSWORD';
FLUSH PRIVILEGES;
SELECT host, user FROM mysql.user;
exit
# Create roundcube database and user.
mysql -u root -p;
CREATE DATABASE roundcubemail CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON roundcubemail.* TO 'roundcube'@'localhost';
FLUSH PRIVILEGES;
exit
# Create mailstore directory for store users mails in this location.
mkdir -p /mailstore/vmail
useradd -r -u 2000 -g mail -d /mailstore/vmail -s /sbin/nologin -c "MyHosted Virtual Mail User" vmail
mkdir -p /mailstore/vmail
chmod -R 770 /mailstore/vmail
chown -R vmail:mail /mailstore/vmail
2021-05-05 15:59:23 +00:00
# Take backup Postfix configuration.
2021-05-05 14:39:14 +00:00
cp -a /etc/postfix /etc/postfix_original
2021-05-05 15:59:23 +00:00
# Take backup Dovecot configuration.
2021-05-05 14:39:14 +00:00
cp -a /etc/dovecot /etc/dovecot_original
2021-05-05 15:59:23 +00:00
# Pull mailserver configuration from github.
2021-05-05 14:39:14 +00:00
cd /root/
git clone https://github.com/harishjadhav26/mail_server.git
2021-05-05 15:59:23 +00:00
# Remove default postfix and dovecot configuration.
2021-05-05 14:39:14 +00:00
rm -rf /etc/postfix
rm -rf /etc/dovecot
# Copy postfix and dovecot new config files.
cp -a /root/mail_server/postfix /etc/postfix
cp -a /root/mail_server/dovecot /etc/dovecot
# Copy postfixadmin and roundcubemail configuration in html.
cp -a /root/mail_server/postfixadmin /var/www/html/
cp -a /root/mail_server/roundcubemail /var/www/html/
# Import postfixadmin and roundcubemail DB.
mysql -u root -p vmailadmin < /root/mail_server/vmailadmin.sql
mysql -u root -p roundcubemail < /root/mail_server/roundcubemail.sql
# Copy dovecot quota script.
cp /root/mail_server/quota-warning.sh /usr/local/bin/quota-warning.sh
# configure SpamAssassin.
cp /etc/mail/spamassassin/local.cf /etc/mail/spamassassin/local.cf_original
cp /root/mail_server/local.cf /etc/mail/spamassassin/local.cf
# PHP config file.
cp /etc/php.ini /etc/php.ini_original
cp /root/mail_server/php.ini /etc/php.ini
# Add new user to run SpamAssassin. ** -g = add to group spamd, -s /bin/false = No shell (does not mean, cannot access via SSH!), -d = home dir **
groupadd spamd
useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd
chown -R spamd:spamd /var/log/spamassassin
# Update the spam rules by running
time sa-update
# Update ownership to dovecot and postfix files.
touch /etc/postfix/sasl_passwd
touch /var/lib/postfix/smtpd_scache
postmap /etc/postfix/sasl_passwd
postmap /etc/postfix/master.cf
postmap /etc/postfix/main.cf
postmap /etc/postfix/sql/*.cf
postmap /etc/postfix/header_checks
postmap /etc/postfix/transport
# Update files permission.
chown -R root:postfix /etc/postfix/sql/*
sudo chmod 0640 /etc/postfix/sql/*
chown -R postfix. /var/lib/postfix/smtpd_scache
# Update postfixadmin and roundcubemail configuration.
chown -R apache. /var/www/html/*
2021-05-05 15:59:23 +00:00
# Update apache virtualhost file.
cp /root/mail_server/httpd/* /etc/httpd/conf.d/
2021-05-05 14:39:14 +00:00
# Service restart.
systemctl enable mariadb dovecot postfix httpd spamassassin php-fpm
systemctl restart mariadb dovecot postfix httpd spamassassin php-fpm
systemctl status mariadb dovecot postfix httpd spamassassin php-fpm
2021-05-06 10:03:18 +00:00
# Dovecot config permission and ownership update.
chown -R vmail.mail /var/run/dovecot/dict
# Send mail from command line.
echo "hello" | mail -r harish@example.com -s "test sub" postmaster@example.com
# Verify mail delivery in maillog.
tail -f /var/log/maillog
2021-05-05 14:39:14 +00:00
# Default password:
PostfixadminDB:
MySQL USER: vmailadmin
Password: STRONGPASSWORD
RoundcubemailDB:
MySQL User: roundcube
Password: password
2021-05-05 15:59:23 +00:00
Postfixadmin:
http://<IP/HOSTNAME>:8080
2021-05-05 14:39:14 +00:00
Superadmin User: postmaster@example.com
Password: password#123
Roundcubemail:
2021-05-05 15:59:23 +00:00
http://<IP/HOSTNAME>
2021-05-05 14:39:14 +00:00
User: postmaster@example.com
Password: password#123
2021-05-05 16:07:40 +00:00
# Reset User Password and DB, Set in Postfixadmin, Roundcubemail, Postfix and Dovecot as per your require meet.
2021-05-05 14:39:14 +00:00
sed -i 's/password = postfixadmin_password/password = STRONGPASSWORD/g' /etc/postfix/sql/*.cf
# Quota update for all domain users.
doveadm quota recalc -u *@*
# Quota verify.
sudo doveadm quota get -A
2021-05-05 16:18:09 +00:00
# Open ports in your firewall application and os level.
2021-05-06 11:55:28 +00:00
Service Software Protocol Port
SMTP Postfix TCP 25
HTTP Apache TCP 80
POP3 Dovecot TCP 110
IMAP Dovecot TCP 143
HTTPS Apache TCP 443
SMTPS Postfix TCP 465
Submission Postfix TCP 587
IMAPS Dovecot TCP 993
POP3S Dovecot TCP 995
ManageSieve Dovecot TCP 4190
2021-05-05 16:18:09 +00:00
# Suggestion use Nginx as frontend server.
2021-05-05 16:20:35 +00:00
LICENSE:
Copyright (c) 2021 Harish <nirahhp999@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.