With the popularity of mobile Internet, email service is used less and less. But to set up an account, you still need an email address. There are many free mailboxes on the market, but generally need to bind the mobile phone number, if you want to register multiple email accounts in the same email service provider, you need to prepare multiple mobile phone numbers, which is very annoying. Let’s build our own mail server.

The preparatory work

Mail servers communicate with each other through SMTP. If our cloud server wants to receive mail, it needs to open port 25 and allow access to port 25.

The special DNS used by the mail service needs to be configured. There are two mappings involved, so for the sake of illustration, let’s say my email name is [email protected]. For the first mapping, add an MX record type to map the host after @mailbox to the domain name, as shown in the following figure. Add an MX record type.

The second mapping maps the above domain name to the IP on our cloud host, and those of you who read the previous article should know how to configure it.

Installing the Mail Service

We will use postfix as the mail server because of its special Settings, we need to first check the hostname of the cloud host and set hostname to the hostname of the mail server.

sudo hostnamectl set-hostname example.com
Copy the code

To install Postfix, run the following command. The popover will let you select configuration and your mail name

sudo apt-get update
sudo apt-get install postfix -y
Copy the code

Once the installation is complete, check to see if the service is started, and if not, postfix Start can be executed.

sudo ss -lnpt | grep master
Copy the code

The mail server is set up. Those of you who have studied computer networks should know that SMTP is only a transfer protocol between mail servers. Pop3 or IMAP protocol is also needed to read mail. So if you want to read mail, you need to install other software. Note: If your Ubuntu has a user1 user, then the mail server has an account for [email protected].

sudo apt-get install mailutils
Copy the code

Receiving Mail test

Next, we use QQ mailbox to send test mail to the newly built mail server, when executing mail on the cloud server

Select 1 to display the content of the email.

If you are careful, you may have noticed that the content of the email is base64 encoded and cannot be read directly. In this case, perform the following decode to select the message and decode it

Postfix can still send mail, but only if the cloud server port 25 is enabled. You can test it yourself on the cloud server to see if port 25 works. If you’re interested in sending mail to Postfix, you can search for information

telnet  mx1.qq.com 25
Copy the code

conclusion

With a self-built email server, you no longer need to worry about having multiple phone numbers