Set up mail server under Linux system (Postfix + Dovecot)

For web sites, sending all kinds of mail registration notification, for example, is a very basic needs, before I have been using Tencent E-mail, I feel very convenient, can directly bind QQ mailbox to receive mail, SMTP site also configure the look it can send e-mail.

But the last few days due to the important information required to immediately notify the user, so I chose the way of bulk mail. In just when I think everything is perfect when it spicy, after another user came over and asked me what I would say to them, please check your email, but several people did not say any mail, so I tried to Zaifayici results returned an error message. Under the Internet to find the cause, then see this: the major free email account SMTP mass mailing SMTP server configuration and delivery volume limit situation , know that this is because the number of letter limit.

After SendGrid, MailChimp, Amazon SES, SendCloud, Mailgun and so on, a lot of people looked at suggestions: so I had to find another way out, and then I found a lot of know almost above provide a mailing service providers, about these I chose Mailgun.

Mailgun register and configure all very simple, I soon successfully sent the first message a feeling of joy to this, I sent a few emails, but tragedy struck in the third message, send a detailed background Mailgun record, this is very good, in the background I see my message was rejected, the reason is probably that the server's IP transmission frequency than Tencent mailbox limit . So here on questions relating to IP, the current third-party mail delivery service is generally shared IP (later also tried SendCloud,), while the share IP and can not determine whether the recipient has reached the limit on the number, once reached will not be able before sending. This means that also need to use a separate IP to ensure that the message has to reach a higher rate, and then they looked at various independent IP price, usually two dozen knives a month or even four dozen United States, which for us this small Mail webmaster demand is not high, it is a bit expensive, buy a VPS do not have the price right.

After these agonizing above, it can be considered to understand if it is to smooth outgoing messages, then, in addition to money, the only built himself a mail server.

Well, let's start into the topic, teach you to build a simple mail server.

Built for server information

Ali cloud Centos 6.5 32 Wei

Installation process

1. Install Postfix

yum -y install postfix

Installation is also need to replace the system comes with sendmail:

rpm -e sendmail
或者
yum remove sendmail

Modify the MTA (default Mail Transfer Agent)

alternatives --config mta

Then directly enter.

Check is not successfully been set up.

alternatives --display mta

The first line can see the status of the mta. E.g:mat - status is manual.

2. Install Dovecot

yum -y install dovecot

3. Configure Postfix

Editor /etc/postfix/main.cf, can be downloaded changes, you can also use vi for editing:

vi /etc/postfix/main.cf

amend as below:

# 75行: 取消注释,设置hostname
myhostname = mail.lomu.me
# 83行: 取消注释,设置域名
mydomain = lomu.me
# 99行: 取消注释
myorigin = $mydomain
# 116行: 修改
inet_interfaces = all
# 119行: 推荐ipv4,如果支持ipv6,则可以为all inet_protocols = ipv4 # 164行: 添加 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain # 264行: 取消注释,指定内网和本地的IP地址范围 mynetworks = 127.0.0.0/8, 10.0.0.0/24 # 419行: 取消注释,邮件保存目录 home_mailbox = Maildir/ # 571行: 添加 smtpd_banner = $myhostname ESMTP # 添加到最后 # 规定邮件最大尺寸为10M message_size_limit = 10485760 # 规定收件箱最大容量为1G mailbox_size_limit = 1073741824 # SMTP认证 smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes smtpd_sasl_security_options = noanonymous smtpd_sasl_local_domain = $myhostname smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject 

Modified after a good use of /etc/rc.d/init.d/postfix startopen postfix, use chkconfig postfix onthe postfix boot.

myhostname = mail.xxxxx.com
mydomain = xxxxx.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname,$mydomain #username@xxxxx.com
#mydestination = $myhostname localhost.$mydomain localhost $mydomain
mynetworks = 127.0.0.0/8, 10.0.0.0/24
home_mailbox = Maildir/
smtpd_banner = $myhostname ESMTP
message_size_limit = 10485760
mailbox_size_limit = 1073741824
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject

Configuring Dovecot

amend as below:

[root@mail ~]# vi /etc/dovecot/dovecot.conf
# 26行: 如果不使用IPv6,请修改为*
listen = *

[root@mail ~]# vi /etc/dovecot/conf.d/10-auth.conf
# 9行: 取消注释并修改
disable_plaintext_auth = no # 97行: 添加 auth_mechanisms = plain login [root@mail ~]# vi /etc/dovecot/conf.d/10-mail.conf # 30行: 取消注释并添加 mail_location = maildir:~/Maildir [root@mail ~]# vi /etc/dovecot/conf.d/10-master.conf # 88-90行: 取消注释并添加 # Postfix smtp验证 unix_listener /var/spool/postfix/private/auth { mode = 0666 user = postfix group = postfix } [root@mail ~]# /etc/rc.d/init.d/dovecot start Starting Dovecot Imap: [ OK ] [root@mail ~]# chkconfig dovecot on 

Here, our mail server has been set up successful.

5. DNS

Finally, do not forget also the need for domain name resolution is working.

Add a subdomain mail, A record resolves to the server IP.

Add an MX record, the host record is empty, DNS records two values above mail.lomu.me, priority 10.

Note: It may take some time to resolve to take effect.

6. E-mail use

After everything is running again, you can use Foxmail and other third-party software to send and receive mail. Here it needs to be said, is the user's mail system users, such as root, is a mailbox user, the mailbox is [email protected], password is the root password, so users need to create, just use useraddto create users, and then set a password using the passwd .

Well, if we create an admin user:

 

# 创建用户
useradd admin
#设置密码,会要求输入两次密码
passwd admin

 

DNS settings:

1, the host name @ Type A ip xx.xx.xx.xx

2, the host name mail Type A

3, hostname mail type mx

Reprinted: https: //www.cnblogs.com/hgj123/p/6186400.html

# 创建用户useradd admin#设置密码,会要求输入两次密码passwd admin

Viewing Error tail -f / var / log / maillog

Note viewing port 110 and port 25 is open 

Open method of ports:

        Method One: the command line

               1. Open Ports command: / sbin / iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

                     8080, be modified according to your own needs 

              2. Save: /etc/rc.d/init.d/iptables save


           3. Restart services: /etc/init.d/iptables restart


           4. Check whether the port is open: / sbin / iptables -L -n

  

      Method Two: directly edit / etc / sysconfig / iptables file


               1. Edit / etc / sysconfig / iptables file: vi / etc / sysconfig / iptables
                   added content and save: -A RH-Firewall-1- INPUT -m state --state NEW -m tcp -p tcp --dport 8080 - j ACCEPT


               2. Restart the service: /etc/init.d/iptables restart


               3. Check whether the port is open: / sbin / iptables -L -n

Published 27 original articles · won praise 53 · views 160 000 +

Guess you like

Origin blog.csdn.net/auspi12341/article/details/79530224