When creating a Web site application, it is an essential operation to send a message to the user when doing some action. The cloud service is a good choice, though. However, if the volume is too small, or subject to certain conditions, the self-built service may be a better choice. The following attempts to build the function of sending mail in CentOS 7.
Install Postfix
Postfix is the MTA (Mail transfer agent) software developed by Wietse Venema under the IBM GPL protocol. Postfix is an attempt by Wietse Venema to offer alternatives to the most widely used sendmail. In the internet world, most emails are delivered via SendMail, and about 1 million users use SendMail to deliver hundreds of millions of emails a day. This is a surprising number. Postfix tries to be faster, easier to manage, more secure, and maintains sufficient compatibility with SendMail.
(Why use Postfix:
1. Postfix is free of charge:
Postfix wants to function as a broad range of Internet users, trying to influence most Internet e-mail systems, so it's free.
2. Faster:
Postfix is about three times times faster in performance than SendMail. A desktop PC running Postfix can send and receive millions of emails a day.
3. Good compatibility:
Postfix is sendmail compatible so that sendmail users can easily migrate to postfix. Postfix supports/var[/spool]/mail,/etc/aliases, NIS, and ~/.forward files.
4. More robust:
Postfix is designed to work properly under heavy load. Postfix automatically reduces the number of running processes when the system is running beyond available memory or disk space. When the number of messages processed increases, the postfix running process does not increase.
5. More flexible:
Postfix is made up of more than a dozen small programs, each of which accomplishes specific functions. You can set the running parameters for each program through the configuration file.
6. Safety
Postfix has multilayer defense structure, can effectively resist malicious intruders. If most of the Postfix programs can run under lower privileges, you cannot access security-related local delivery programs, and so on. )
Postfix is now almost standard with the MTA (Mail Transfer Agent). But before it Sendmail is standard. So in some old system versions, you need to remove Sendmail when installing Postfix. If the system already has Postfix installed, you can skip this step.
Use the following command to view the MTA conditions used by the system:
The code is as follows:
Alternatives--display MTA
Delete Sendmail
The code is as follows:
sudo yum remove SendMail
Install Postfix
The code is as follows:
sudo yum install postfix
Set Postfix to MTA
The code is as follows:
sudo alternatives--set mta/usr/sbin/sendmail.postfix
Configure Postfix
Edit the following configuration in the/etc/postfix/main.cf file:
The code is as follows:
Myhostname = mail.dyniao.com # host Name
mydomain = dyniao.com # mail server's primary domain name
Myorigin = $mydomain # Send the domain name displayed in the message
Inet_protocols = IPv4 # Supported network protocol
The above configuration is only the smallest configuration I can run while testing, please do not use for formal or production environments.
Start Postfix:
The code is as follows:
sudo service postfix start
Let Postfix support boot up:
The code is as follows:
sudo systemctl enable Postfix.service
Domain name Configuration
By completing the above steps, you can already send mail to any mailbox. But usually they can only be found in each other's trash bins. To avoid this situation, you also need to configure the host domain name resolution so that the server that receives the message trusts the incoming message. The steps are as follows:
Add a a record, set the domain name of the mailbox, such as: mail.zzxworld.com, point to host IP.
Add an MX record, point to the mailbox name that you added in the first step.
Add a TXT record with a record value of:
The code is as follows:
V=SPF1 a MX ~all
The record value above indicates the use of SPF (Sender Policy Framework) to prevent others from forging messages.
After the domain name resolution is in effect, you can send mail from the host normally.