Postfix Mail Relay

Postfix is a flexible and powerful mail transfer agent service. Here, it will be used as a relay to send local messages to an external mailbox.


Install the packages:

sudo apt install -y postfix mailutils libsasl2-2 libsasl2-modules ca-certificates ssl-cert


Edit the file /etc/postfix/, replacing "" with the mail service you wish to relay email through.

mynetworks =, [::1]/128
inet_interfaces =
relayhost = []:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

Then, add the credentials for the mail relay to /etc/postfix/sasl_passwd


After editing the file, update the hashed credentials:

sudo postmap /etc/postfix/sasl_passwd


Aliases determine where mail will be routed for local users.

Edit the /etc/aliases file and fill it in with your email addresses:

postmaster: root

#An example

After editing the file, regenerate the aliases database:

sudo newaliases

Send emails

Send an email to the root user:

echo "Hello, root!" | mail -s "A message for Charlie Root" root

A message should be delivered to your mailbox shortly.