A foreword

Originally used qq E-mail , And then with the help of sendEmail To send email alerts , But there are daily 200 No restrictions , It's very unpleasant , So I want to build my own mail server to solve this problem , About use sendEmail With the help of qq Email to send mail, see http://www.cnblogs.com/Dicky-Zhang/p/5982973.html, Before doing this , I searched a lot of information on the Internet , It's chaotic , Not one , Put it together , It's impossible to use , So write it down , Convenient for later use .

Doing it postfix Before , I successfully built iredmail, A powerful open source system . I'll write another article about the process later , For your reference .

Under the instructions

About Alibaba cloud's e-mail system , Alibaba cloud is right about 25 Ports are limited , Even if you do , It may not be available on third party servers , I did it on this machine , Can't use . For Qingyun system , The default is no opening to the outside world 25 port , The opening up here is not in the server , You need to open it backstage 25 port , Otherwise, you will be prompted to time out when you connect to the server , I didn't test foreign servers , I don't think there should be any restrictions . Okay , Not much said , Get down to business

Explain a few nouns

  • MUA: User agent side , That is, the letter used by the user 、 Receiving client software . such as :outlook、foxmail Wait for the client software , Even through the browser login mailbox and send mail BS Web architecture is also MUA.
  • MTA: Mail delivery side , It's commonly known as the mail server , For forwarding 、 Receiving user mail . In this article postfix What is achieved is MTA, Of course postfix It's a special one MUA, I won't go into it any more , In this paper, only postfix treat as MTA Use .
  • MDA: Mail proxy , amount to MUA and MTA The broker in , Can be used to filter spam .
  • POP: Post office protocol , Now it's the Third Edition , That is to say POP3, be used for MUA Connect to the server to receive user mail , Communication port 110.
  • IMAP: Internet Application Protocol , Function and POP similar : Also used in MUA Connect to the server to receive user mail ; It's more functional POP many , Communication port 143.
  • SMTP: Simple mail delivery protocol ,MUA Connect MTA or MTA Connect MTA Send mail using this protocol , Communication port 25, Enable ssl/tls In this case, the port is 465 or 587.

The general email process is :

1、MUA adopt POP、IMAP or SMTP Protocol connection MTA( be called mta1); In this article php adopt phpmailer Request to send mail php The script plays MUA Role , and postfix Namely MTA;

2、MUA Send an email to mta1( Or say MUA adopt mta1 Send E-mail ); In this paper postfix This is this. mta1;

3、mta1 With other MTA Autonomous communication connection will send mail to the specified users in the specified domain ( here mta1 Just play MUA The role function of , This kind of interaction is realized by the mail system software , Nothing to do with the client ).

This construction postfix The purpose is clear :

  • be used for php Developed web Send verification code e-mail when new users register in the environment ---php Pass through phpmailer The class library smtp Protocol Links postfix To send mail .
  • web Environment and postfix At the same table CentOs6.5(64 position ) Under the system ,postfix No external supply smtp And don't forward it to the outside MUA mail , Just forward ( Or send )web In the environment (MUA) The mail , That is, only forward the local machine ( Or the domain ) mail . At the same time, we don't accept other MTA The mail ( In other words, don't accept email from others ).
  • This article will not introduce postfix、sasldb2、saslauthd Waiting for the software , A lot of Internet

Two postfix Installation

 yum remove sendmail # uninstall sendmail
yum remmove postfix # uninstall postfix
yum install postfix # reinstall postfix
#yum The installation will automatically create postfix User groups and user names
yum install crontabs # Because uninstall postfix The timing service of the system is also unloaded Core services Also synchronous installation

Use sasldb、saslauthd To generate smtp Virtual Account


 yum install cyrus-sasl* # Provide smtp Virtual account and password Services 
#sasldb2 Included in saslauthd among Don't ask why it's not installed sasldb2 Of shell Code.
# At present mta see
alternatives --display mta
# Set up mta
/usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix
# Look again mta
alternatives --display mta
# The last line of the output will have a prompt similar to the following :mta That is, the setting is finished
#Current `best' version is /usr/sbin/sendmail.postfix.

postfix Boot up settings , Because of the adoption of sasldb2 Provide postfix Of smtp Account and password , There is no need to saslauthd Service running , so saslauthd The service doesn't need to be started , Use sasldb2 It also reduces resource consumption :

chkconfig postfix on

3、 ... and postfix Configure and enable smtp

postfix Configuration file in /etc/postfix Under the table of contents , The main modified configuration file is :/etc/postfix/main.cf, See the code section for configuration instructions

 vi /etc/postfix/main.cf #vi edit postfix The configuration file 
# Find the following configuration items and modify them as appropriate
myhostname = mail.xxx.com.cn
#postfix Host name , Change to your domain name This item needs to be added A Record and point to postfix The host is on the public network IP
mydomain = xxx.com.cn
# domain name
myorigin = $mydomain
# This machine postfix The most popular email domain name The default value for this item is myhostname
# The preceding item is used here mydomain That is to say, this machine postfix The mailbox suffix is :@xxx.com.cn
inet_interfaces = all
# Appoint postfix Network interface for system monitoring This must be localhost or Or Intranet ip
# If you annotate or fill in the public website ip Server's 25 The port will be open to the public network
# The default value is all That is to listen to all network interfaces
# This specifies localhost after This machine postfix You can only send mail, you can't receive mail
inet_protocols = ipv4
# Network protocol ipv6 It's not very popular in China here ipv4 that will do
mydestination = $myhostname, localhost.$mydomain, localhost
# Appoint postfix The recipient's domain name when receiving e-mail , let me put it another way , It's your postfix What kind of mail does the system want to receive .
# In this configuration $myhostname Express postfix Accept @$myhostname Mail for suffix mailbox Comma split support refers to multiple
# The default value for this item is myhostname
local_recipient_maps =
# This item sets the rules for receiving mail It can be hash file This item has no meaning for this configuration You can annotate it directly
mynetworks = x.x.x.x
# Specify the network address of your network
# It's better to add the server you want to use on a third party , If not, it may not be used on a third party
# Please revise according to the actual situation
smtpd_banner = JJonline.Cn ESMTP Server
# Appoint MUA adopt smtp Connect postfix When the returned header Header information
# The original configuration comes with postfix Version number Remove it , This is discretionary
#SMTP Config
broken_sasl_auth_clients = yes
# Appoint postfix compatible MUA Use irregular smtp agreement -- Mainly for the old version of outlook This item is meaningless for this configuration
smtpd_client_restrictions = permit_sasl_authenticated
# Specify that you can send to postfix launch SMTP The host name or ip Address
# here permit_sasl_authenticated It means to be allowed to pass through sasl authentication ( That is to say smtp Link through the account 、 Password validation users ) All users of
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
# The sender is executing RCPT TO The address provided during the command is restricted by the rule Copy here
smtpd_sasl_auth_enable = yes
# Appoint postfix Use sasl verification Popular will be to use smtp And ask for an account number 、 Password validation
smtpd_sasl_local_domain = $mydomain
# Appoint SMTP Certified local domain name This configuration can use smtpd_sasl_local_domain = '' Or just comment it out The default is empty.
smtpd_sasl_security_options = noanonymous
# Cancel smtp Anonymous login for The default value for this item is noanonymous smtp If you can login anonymously, it will do great harm Be sure to specify this as noanonymous
message_size_limit =
# Designate to pass postfix The size of the sent mail Here said 5M

see postfix All configuration items of the configuration file :

 postconf # Without any command parameters You can output all postfix Configuration items and default values 

postconf # Without any command parameters You can output all postfix Configuration items and default values

Four sasldb2 establish smtp User and password

In a sense :smtp The establishment of account password is the establishment of e-mail account

# To configure postfix Enable sasldb2 As smtp The secret verification method of account number 
# The editor passed sasl Enable smtp Configuration of account password validation
vi /etc/sasl2/smtpd.conf #vi Write or edit as follows :
pwcheck_method: auxprop
auxprop_plugin: sasldb
mech_list: plain login CRAM-MD5 DIGEST-MD5
# What needs to be noted here is : The location of this configuration file is 64 On the machine ,32 Bit machine should be in :/usr/lib/sasl2/smtpd.conf # establish smtp account number
saslpasswd2 -c -u `postconf -h mydomain` test # Enter will ask for the password , Two consecutive times
# Representation creation [email protected]$mydomain My email account number ( It's also smtp Account number ) And password
# This example is to create [email protected] Account and password
# The point here is smtp The login account is not just a user name It's the entire mailbox address string
# Let's assume that smtp account number [email protected] The password for test123 In the test below, we need to use # see sasldb2 User and password
# This command can be viewed by the user sasldb The user profile of
# This command returns and outputs something like this :[email protected]: userPassword # Add every time smtp The user needs to restart after finishing postfix or reload

test postfix Profile and start postfix

 # test postfix The configuration file 
service postfix check
# If there is no problem, it will return to coloring [ok] word
# start-up postfix
service postfix start
# Set up postfix Boot up
chkconfig postfix on
# change sasldb2 Data permissions , Give Way postfix Can read
chmod /etc/sasldb2

5、 ... and   test smtp

Direct local telnet, The above added [email protected] Account number and test123 The password needs base64 code , The encoded string is :

Execute the encoding statement :

user name :perl -e 'use MIME::Base64; print encode_base64("test")'


password :perl -e 'use MIME::Base64; print encode_base64("test123")'


telnet test :

Test on this machine :

telnet  localhost  25

 # If not installed telnet To be installed telnet
yum install telnet #telnet test smtp Connect postfix
telnet # After entering, it will be displayed by $smtpd_banner Configuration welcome message
EHLO jjonline # Input ehlo The header shakes hands The message returns and continues
AUTH LOGIN # Request for smtp Account password validation
Enter... After returning test Of base64 code , yes test instead of [email protected]
# Enter... After returning test123 The code of the password It's also base64 code
# When you enter, it will show smtp It works Next, you can test the function of sending e-mail This article will not do an example # Be careful To exit telnet Input quit You can enter.

Since then , build by oneself postfix And enable the smtp and smtp The virtual account of 、

Explain a little :

If you want to use it on a third party , You can test it on a third-party server first , still telent mail.xx.com( Your mail server ), It's basically the same as above , If the test passes , Basically, it can be used by a third party . If the configuration is correct , But there's something wrong with the test ,telnet Overtime , Please contact your space provider at this time , Let him go 25 port .

6、 ... and   Domain name resolution record settings

postfix configured , Want to get through this postfis The mail sent by the mail server is accepted by other mailbox service providers , Still need to be done A Record 、txt Record also mx Record , Please match your own domain name and ip Address

7. Use it on a third party server

1, Use sendEmail To send mail

Usage as shown in the :http://www.cnblogs.com/Dicky-Zhang/p/5982973.html

Let me just put it briefly :

And use qq It's a little different , Here is to enter the user name and password directly , Not the encoded user name and password

2, Use mail perhaps mailx To call the mail server to send mail

Need to install postmail perhaps sendmail service , The installation method is relatively simple ,yum That's all right.

Some configurations are as follows :

 Open profile vim /etc/mail.rc
Add the specified value to the last edge
set [email protected] ( Sender )
set smtp=mail.xxx.com ( Mail server )
set smtp-auth-user="xxxx" ( user name )
set smtp-auth-password=""( password )
set smtp-auth=login The user name and password do not need to be encoded
Save restart service

Here's the test , About mail,mailx usage , Click here http://www.cnblogs.com/Dicky-Zhang/p/6085212.html

8. White list

I'm habit net qq Email in the mailbox , So pay attention to the white list , Self built mail servers are likely to be treated as spam , It's in the trash , So we need to set up a white list

open qq mailbox


In this way, we can receive our email all the time

Reference link :


CentOS6.5_64 Bit system postfix Mail system Enable and configure SMTP More related articles on using email on third parties

  1. CentOS6.5_64 Bit system postfix Mail system Enable and configure SMTP Virtual accounts

    http://blog.jjonline.cn/linux/185.html http://www.cnblogs.com/apexchu/p/4271264.html Add and delete users http:// ...

  2. Centos6.5_64 Installation under bit system Oracle 11g

    One . Hardware requirements 1. Memory and Sweap: Memory 2G( above ),Sweap 2G( above ) Memory : 1-2G 2-16G 16G above Sweap: 1.5 Double memory 1 Double memory 16G Check :# grep MemTot ...

  3. win8 64 Bit system , install JDK And its environment configuration

    Tools / raw material jdk-8u51-windows-x64.exe Download address :::http://www.cr173.com/soft/55503.html#address jdk Installation steps 1: To oracl ...

  4. win7 64 Installation under bit system autoitlibrary Library encountered a problem solving

    Reprint from http://blog.sina.com.cn/s/blog_53f023270101skyq.html Today we need to be in win7 64 Installation under bit system autoitlibrary library , At first it was installed robo ...

  5. Linux Installation under system Redis and Redis Cluster configuration

    Linux Installation under system Redis and Redis Cluster configuration One . download . install . Configuration environment : 1.1.> Official website download address : https://redis.io/download ( What I download is 3.2.8 edition :re ...

  6. win10_64 Installation under bit system ALM12.01(QC), The author is only in Win10 I tried it on the platform , You can also go to win7 Try it on our platform , A truth !(Alpha)

    HP Of ALM It's a very comprehensive defect management system , But the installation of learning is very troublesome , I used to learn ALM, I haven't used it for a long time. Today, I want to learn about it and find it very difficult to install it ! Find online right ALM The introduction of system installation is very little , It's also very trivial ! Learn by yourself today ...

  7. The virtual machine Linux Installation of graphical interface under minimum system , And yum To configure

    For unknown reasons , I want to install it . Because there are CDs , So just install it from the CD . The first is configuration yum Download address under : find yum The address of , Then open the file . And then create the /media/cdrom route . Mount the CD to this path . ...

  8. Linux in CentOS6.5 64 position Installation under system docker step

    CentOS6.5 64 position     (docker Currently only supported 64 position ) The kernel must be in 3.10 And above 1. uname -r  View kernel version 2. Upgrade the kernel to 3.10 edition ( belt aufs modular )    cd /etc ...

  9. Windows 64 Installation under bit system JAVA Environmental Science

    File name :jdk-7u51-windows-x64 download Windows 64 Platform JDK The installation files . install 1. Double click to open the downloaded file , Click on “ next step ” Start installation . 2. ① The default option is to install all features , No adjustments . ...

Random recommendation

  1. To stay in cnblogs The first essay Hello, world!

    When searching for computer reference materials on the Internet, I often see the blogs of the gods , I'm fascinated by . Today I'm also settling down here , Record your learning process , I would also like to share with you . The first essay , Let's test the text editor here . //The C language # ...

  2. Reading Wu Jun " And " series

    Reading Wu Jun " And " series This year and two years , Read Mr. Wu Jun ( Microblogging , Know about columns ) My books take up quite a lot of my time . Read Mr. Wu Jun ( Microblogging , Know about columns ) The book of , It will make you admire , Can't help but ask " Why are some authors so rich ...

  3. Extjs adopt structs2 Spanning tree structure

    Extjs Provides us with a powerful way to generate trees , We don't have to go through the original js To generate a tree structure . Here I do a simple tree structure generation . The code is as follows , At the same time, it is used in the background fastjson-1.1.15.jar Of jar Package generation json ...

  4. centos 6.7 perl edition This is perl 5, version 22 install DBI DBD

    <pre name="code" class="cpp">centos 6.7 perl edition This is perl 5, version 22 ...

  5. POJ 2774 Long Long Message( The suffix array )

    [ Topic link ] http://poj.org/problem?id=2774 [ The main idea of the topic ] Find the longest common substring [ Answer key ] Connect two strings with a character embedded in the middle , Find the suffix array If the beginning of two suffixes adjacent to each other in the ranking belongs to two ...

  6. .Net Event bus Autofac decoupling

    The event bus is through an intermediate service , Publications and subscriptions stripped of regular events ( consumption ) A technical realization of strong dependence . For the basic knowledge of event bus, please refer to Shengjie's blog [ How much does event bus know ] This blog will not give a detailed overview of event bus basics , Core point placement and use Aut ...

  7. Fence Repair POJ - 3253 ( greedy )

    Farmer John wants to repair a small length of the fence around the pasture. He measures the fence an ...

  8. python3 json modular

    import json ''' hold python Object to json strand ( character string ), ensure_ascii Deal with Chinese code '''dic = {" multiple 4": " Good-looking? ", ...

  9. Effective Java The third edition ——76. Strive to maintain the atomicity of failure

    Tips The source code address in the book :https://github.com/jbloch/effective-java-3e-source-code Be careful , Some of the code in the book is based on Java 9 API Medium , the ...

  10. IP Routing configuration ---------debugging debugging

    Experimental equipment : Huasan equipment N Taiwan plus one PC Step one , Turn on the screen output switch , Turn on the console to monitor the system information <H3C>terminal debugging #<H3C>terminal mon ...