Ubuntu 22, installing the email server

Search for a command to run...

No comments yet. Be the first to comment.
...Hand over your flesh, and a new world awaits you. We demand it. The AI revolution is arriving at the worst moment possible, but it is here, and it will not get away. Workforce (aka, the flesh) In
Currently, I am working on a 500k lines code project. It is strictly structured, OOP, Models, Services, Controllers, and whatnot. Sadly every time we need to make changes to the code, it gets harder and prone to errors. PHP is funny but in the long r...

A PHP library to run multiples processes using JavaScript

I want to install a cheap NAS to backup and keep some files locally in my house. What is a NAS?. NAS is a machine to serve data (videos, documents, backups) using the network but it also could work to serve other purposes, such as audio and video str...

That is the trick Change the edge link to: "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --enable-features=msEdgeAreaSelect Thank Microsoft for making our life easy.

It is a fast and complete guide to installing an email server using Ubuntu 22 but it should work too with Ubuntu 16 and higher.
Postfix is our tool that does the heavy-lifting. It will also install other services. What postfix does in the background is overly complex but we will only touch the surface of it.
apt install postfix
It will show the next screens:









And reload the service
systemctl reload postfix
You can re-configure the system using the next command (or you could edit the configuration file manually)
sudo dpkg-reconfigure postfix
Indicates the mail folder:
postconf -e 'home_mailbox= Maildir/'
And restart postfix.
sudo systemctl restart postfix
In the folder /etc/postfix, you could find many files. There are two important files, one is main.cnf and master.cnf.
You must allow the services to pass the firewall.
sudo ufw allow Postfix
If you want to receive emails, then you must open the port TCP/IP 25 from your firewall.
Note: If you are using AWS, then you must ask permission to Amazon (and open the firewall), otherwise it will not work. And as far as I know, Azure put the same restrictions. Many cloud providers could put their own restrictions, some simply deny the use of the port 25.
Most home connections block the port 25.
How to test if the port is open?
In a different machine, runs the next command:
telnet <external-ip> 25
If you are using Windows, then you can use Putty (a free program) and try to do telnet using port 25.
Log in with the user and run the next command
mkdir ~/Maildir
mkdir -p ~/Maildir/{cur,new,tmp}
chown -R USERNAME:USERNAME ~Maildir
Where username is your username
To install a client compatible with postfix, you can use Mutt.
yum install mutt
There are many clients but it is easy and minimalist.
The other popular client is s-nail but it is less intuitive.

Note: You must configure the DNS before you want to send email. It could work locally but it is better to test it with the DNS up and running.
Open mutt
mutt
And select "m" (mail)
Fill in the information in the email. And finally, send it "y"

You can send an email using the next command.
echo "body" | mail -s "title" <your email>
Configuring the DNS
How do you know that it is working?
You can check the log at:
cat /var/log/mail.log
Finally, you will need to configure your DNS.
Go to the DNS configuration and enter the next information:
type | name | content | priority |
MX | <your domain> | <your domain> | 10 |
TXT | _dmarc | v=DMARC1; p=none; rua=mailto:sender@<domain> | |
TXT | <your domain> | v=spf1 ip4:<your IP> ~all |
|
Change <domain> by your domain and <your IP> for the private IP of the server.
Note: Gmail did some changes to the SPF entries. It does not accept includes or domain names, only IPs.