How to Install and Configure Postfix on Ubuntu without real domain

Hey everyone!

Hope you are safe and doing great!

Someday, maybe you have the idea - of how to create your own SMTP eMail server which will send eMails to various real eMail addresses?

In this guide, we will go through the short setup, as the result, you will be able to send eMails to eMail providers, which are not blocking senders without real domains. (For example - your personal eMail server or corporate one.)

In the example, we are using Ubuntu 22.04 machine. But of course, you can use any other proffered Linux distro. Do not forget that some commands can be different on different Linux distros.

We will not cover TLS, SPF, and DKIM in this guide as it is out of the current scope.

So let's start!

1. Installing Postfix

1.1. Installing mailtuils will install Postfix and some other required dependencies as well

sudo apt install mailutils -y

1.2. Choose Internet Site and hit Ok

1.3. Type any domain (even if it does not exist in real life OR already belongs to some other person or company and so on) which you want to be as your sender domain and hit Ok

1.4. Verify that Postfix is running on your server

service postfix status

or

systemctl status postfix

2. Configuring Postfix

2.1. Now let's configure Postfix to process requests and send emails

sudo nano /etc/postfix/main.cf

2.1.1. Change parameters
2.1.1.1. inet_interfaces = all
to inet_interfaces = loopback-only
2.1.1.2. myhostname = SomeParameterHere
to myhostname = localhost
2.1.1.3. mydestination = SomeParameterHere
to mydestination = $myhostname, $mydomain
2.1.2. Add parameters
2.1.2.1. mydomain = PutYourDomainHere
2.1.3. Save changes and exit
2.1.3.1. Press CTRL+O and Enter to save the file
2.1.3.2. Press CTRL+X to close the file

2.2. Add your domain which is pointed to your server IP address

sudo nano /etc/hosts

2.2.1. Add the line to the file
2.2.1. 127.0.0.1 PutYourDomainHere
2.2.2. Save changes and exit
2.2.2.1. Press CTRL+O and Enter to save the file
2.2.2.2. Press CTRL+X to close the file

2.3. Update the server name

sudo nano /etc/hostname

2.3.1. Change to PutYourDomainHere
2.3.2. Save changes and exit
2.3.2.1. Press CTRL+O and Enter to save the file
2.3.2.2. Press CTRL+X to close the file

2.4. Restart Postfix service

sudo systemctl restart postfix

2.5. Reboot the server for updating

sudo shutdown -r now

or

sudo reboot

2.5. Try to send an email

echo "This is the body of the email" | mail -s "This is the subject line" mail@mail.com

Change mail@mail.com to your recipient's eMail address

2.6. Check the mail logs

tail /var/log/mail.log

You are awesome!

That is it. Hope this short guide helped you and saved your time for the best.

Thank you for reading and see you soon.