Shell scripts to automatically install internal mail server --postfix

Summary:

Postfix is ​​Wietse Venema of IBM under the GPL protocol developed by MTA (Mail Transfer Agent) software. postfix is ​​Wietse Venema want to try to provide a substitute for the most widely used sendmail. In the Internet world, most of the e-mail is delivered to by sendmail, about 100 million users use sendmail, delivering hundreds of millions of messages per day. This is really a digital surprise people. Postfix attempts to faster, easier to manage, more secure, while also maintaining sufficient compatibility with sendmail.

Set up E-mail benefits:

1. comprehensively promote a unified corporate image, to facilitate the promotion of corporate image, while maintaining an easy product.
2. For employee turnover, resulting in leakage of information and resources can not be retained to provide a guarantee; inevitably take mail if employees use personal email, leave;
3. facilitate enterprise unified management, set permissions, and nothing in other classes, to facilitate the exchange of information within the enterprise communication and assistance;
4. better than the personal mail of stability, security and service;
5. overseas forwarding server, so the message to the foreign exchanges is not easy to lose and bounce messages.
6. There are some other functions, such as preventing viruses, SMS alerts, e-mail fax, backup, monitoring

Scripting Environment

1.linux centos 7 system
2. The system can be connected to the external network
3. Network Mode: NAT mode

Experimental Procedure

1. Upload postfix script to the Linux system / root directory

chmod + x * .sh add execute permissions

2. Detailed script postfix.sh

#!/bin/bash

# Automatic acquisition segment native
NET = the ifconfig ens33 `| grep" Netmask "| awk 'Print $ {2}' | Cut -C 1-9`
# automatic access to the local IP
IP =` ens33 the ifconfig | grep "Netmask" | awk '{print $ 2}' `

# Postfix download the relevant software packages
down_postfix ()
{
# turn off the firewall, security
systemctl STOP firewalld
setenforce 0
echo -e "\ 033 \ t [34m Downloading postfix related packages ... \ 033 [0m" && SLEEP 1
yum install the bind postfix Dovecot -Y
}

# Modify configuration files
setup_file ()
{
echo -e "\ 033 \ t [34m is being modified DNS configuration files ... \ 033 [0m" && SLEEP 1
# Edit DNS master configuration file
# allow all ports to listen
sed -i "13s of / 127.0.0.1 / the any /" /etc/named.conf
# allowed to receive all segments
sed -i "21s / localhost / any /" /etc/named.conf

# Editing area to modify the configuration file
# define the domain name and profile data area
sed -i "24i Zone \" \ benet.com \ "\ the IN {\ the n-\
of the type Master; \ the n-\
File \" \ benet.com.zone \ "\; \ n-\
the allow-Update {none;}; \ n-\
};" /etc/named.rfc1912.zones

# Create a positive resolution files
cp -p /var/named/named.localhost /var/named/benet.com.zone
# add an administrator mailbox
sed -i "2s / rname.invalid. / Admin /" / var / named /benet.com.zone
# add local ip address
sed -i "9S / 127.0.0.1 / $ ip /" /var/named/benet.com.zone
# specifies the mail exchange record
sed -i "10c IN MX 5 mail .benet.com. "/var/named/benet.com.zone
# host address resolve
echo" mail the IN A $ IP ">> / var / the named / benet.com.zone
# add a native hosts file parsing
echo" $ ip mail.benet.com ">> / etc / hosts

# Postfix modify the relevant configuration file
echo -e "\ 033 \ t [ 34m is being modified postfix configuration file ... \ 033 [0m" SLEEP 1 &&
# modify Outgoing server hostname
sed -i "75c myhostname = mail.benet .com "/etc/postfix/main.cf
# modify Outgoing server domain
sed -i" 83c of mydomain = benet.com "/etc/postfix/main.cf
# modify sender address of the mail domain
sed -i" 99s / # // "/etc/postfix/main.cf
# ip address for open listening All
sed -i" 113S / # // "/etc/postfix/main.cf
# closed only monitor local ip
sed -i" 116s / ^ / # / "/etc/postfix/main.cf
# set the message storage location
sed -i" 419S / # // "/etc/postfix/main.cf
# modify recipient e-mail addresses and domain names
sed -i '164c mydestination = $ mydomain, $ myhostname '/etc/postfix/main.cf

# Devocot modify the relevant configuration file
echo -e "\ 033 \ t [ 34m is being modified devocot configuration file ... \ 033 [0m" && SLEEP 1
# open pick-up service
sed -i "24s / # / / " / etc /dovecot/dovecot.conf
# Write arrangement allows network segments
Sed -i "= $ net.0 login_trusted_networks 48c / 24" /etc/dovecot/dovecot.conf
# open position and format of the mail
sed -i "24s / # / / "/etc/dovecot/conf.d/10-mail.conf
}

# Restart all services
restart_service ()
{
# dns Restart Service
systemctl the restart the named
# inspired weight member postfix service
systemctl the restart postfix
# dovecot restart the Write service
systemctl the restart dovecot
}

#函数汇总
main()
{
down_postfix && setup_file && restart_service
}

# Perform all the functions
main

3. Verify script

1. The execution of the script

Run the script ./postfix.sh #

2. Review the service port

Shell scripts to automatically install internal mail server --postfix

3. Create a test user zhangsan, lisi

groupadd mailusers # to add a user's mailbox test
useradd -g mailusers -s / sbin / nologin zhangsan # add zhangsan user
useradd -g mailusers -s / sbin / nologin lisi # add lisi user
passwd zhangsan # zhangsan set password
passwd lisi # Set Password lisi

Knowledge points to explain:

useradd -g mailusers -s / sbin / nologin zhangsan add zhangsan users to join the group without logging in linux system
and useradd zhangsan can log on linux system
user who created 2 can log mailbox, created in different ways, it can be mutually send mail, mailbox aspects will not be affected!

3. Install Foxmail

1. Download the official website address: https://www.foxmail.com/ , choose windows or mac version version.

2. The first set up a local computer dns server address
Shell scripts to automatically install internal mail server --postfix

Note: 192.168.0.1 is routing gateway computer is a local address in order to connect the external network
192.168.0.200 is dns server addresses, in order to resolve the domain name mail.benet.com

3. Run the installed Foxmail, set up an account, click on the manual settings
Shell scripts to automatically install internal mail server --postfix

4. Set up email accounts, passwords, pop server, SMTP server, the other the default, click Create, complete
Shell scripts to automatically install internal mail server --postfix
Shell scripts to automatically install internal mail server --postfix

5. Right-click Settings under zhangsan account, create user lisi, set up with the user zhangsan
Shell scripts to automatically install internal mail server --postfix
Shell scripts to automatically install internal mail server --postfix

6.zhangsan user wrote to the user lisi
Shell scripts to automatically install internal mail server --postfix

7.lisi receiver View
Shell scripts to automatically install internal mail server --postfix
8.lisi reply test
Shell scripts to automatically install internal mail server --postfix
10.zhangsan receiver test
Shell scripts to automatically install internal mail server --postfix

Pit explain

  以上操作教程只用于虚拟机演示,做实验部分。若是真实公司搭建内网邮箱,是不会这么顺利的,会出现很多问题

One problem: some computer mailbox smooth landing, but some computer failure E-mail

Shell scripts to automatically install internal mail server --postfix

Second problem: the beginning of mail are normal, after some time, found that e-mail transmission failed or recipient fails.

Shell scripts to automatically install internal mail server --postfix

Analysis: The reason for this problem may be due to DNS failure, or build their own dns server resolves instability

Solution:

Method 1. Add the local hosts file parsing

Shell scripts to automatically install internal mail server --postfix
Shell scripts to automatically install internal mail server --postfix

2. Fill method when setting the IP address instead of the domain name server

Shell scripts to automatically install internal mail server --postfix

After several tests, I found the most convenient and most stable program is the following four steps:

1. dns service directly without building postfix service

2. Fill dns server address is not local, it can automatically get

Shell scripts to automatically install internal mail server --postfix

3. Add the local hosts file parsing (see FIG. 1)

4. Fill in the IP address instead of the domain name server settings (all users must do step)

Shell scripts to automatically install internal mail server --postfix

NOTE: 1,2,3 step is to choose to do step 4 is a must-do steps to insurance, operating about four steps are the best!

Other pit:
Mac system logon failure, which is due to foxmail mac version and Windows version is not the same account settings

Solution: Fill in the following figure account information
Shell scripts to automatically install internal mail server --postfix

to sum up:

1. The company set up mail server LAN recommend using postfix
2. script file does not recommend direct copy, you can download my data
structures 3. This paper mail server is the server within the company, including the network can only be used outside the network to use You need to apply outside the domain name.

Guess you like

Origin blog.51cto.com/13760351/2426593