How to Install Postfix on Debian Latest

Postfix is a popular mail transfer agent (MTA) used to route and deliver email on Linux and Unix systems. In this tutorial, we will install Postfix on Debian Latest.

Prerequisites

Before you start, ensure you have:

Step 1 - Update System Packages

Ensure that your Debian Latest system is up to date by running:

sudo apt update
sudo apt upgrade

Step 2 - Install Postfix

To install Postfix on Debian Latest, run the following command:

sudo apt install postfix

During the installation, you will be prompted to choose a mail server configuration option. Choose Internet Site and press Enter.

In the next screen, enter your system's fully qualified domain name (FQDN) (e.g. example.com) and press Enter.

Step 3 - Configure Postfix

Postfix's primary configuration file is located at /etc/postfix/main.cf. We'll make some changes to this file to configure Postfix.

sudo nano /etc/postfix/main.cf

Add the following lines at the end of the file to configure Postfix to use Google's SMTP server to send email:

relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

Save and close the file.

Step 4 - Create Authentication Credentials File

Create a file /etc/postfix/sasl_passwd with the following contents:

[smtp.gmail.com]:587    USERNAME@gmail.com:PASSWORD

Replace USERNAME@gmail.com with your Gmail account's email address and PASSWORD with your Gmail account's password.

Secure the authentication file by running:

sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd

Step 5 - Restart and Test Postfix

Restart Postfix by running:

sudo systemctl restart postfix

Test if Postfix is working by sending a test email:

echo "This is a test email" | mail -s "Test Email Subject" recipient@example.com

Replace recipient@example.com with the target email address.

If the email is sent successfully, you'll receive a message in your inbox.

And you're done!

Postfix has been successfully installed and configured on your Debian Latest server. You can now use it to send email from your server or applications.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!