Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Ubuntu: Install Postfix with mail forwarding #Ubuntu #Markdown #Postfix


Postfix is a commonly used MTA (Mail Transfer Agent) program that can receive, deliver or route emails. In this guide you'll learn how to forward mails from a certain domain to another e-mail address. It's a recommanded approach if you want to publish a mail contact based on your domain and redirect the received mails to another provider, such as Outlook or Gmail.



Install Postfix with aptitude.

sudo apt-get install postfix

In the wizard chose as showed below.

Setup type: Internet Site
System mail name: <domain>

After the installation check, wether the Postfix agent is running or not.

sudo service postfix status

Verfify your mail DNS records. Here's an example.  85100  IN  MX  10  85045  IN  CNAME

Also Verifiy open Ports, postfix is accessable via these ports.

smtp port 25

We assume the mail server runs on the web server.

Let's configure the postfix server.

sudo vi /etc/postfix/

Add at these line at the end of the file.

# acceptable mail domains for postifx
virtual_alias_domains =
virtual_alias_maps = hash:/etc/postfix/virtual

Lets add some mail forwarding rules

sudo vi /etc/postfix/virtual

Now you can add your mail adresses, here's an exmaple with gmail.

Update the postfix lookup table

sudo postmap /etc/postfix/virtual

Restart the postix service

sudo service postfix reload

And last check wether the config has been load propberly

postconf -n | grep virtual

You should see the virtual config instructions


Setup mail forwarding in postfix on Ubuntu or Debian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment