Tuesday Sep 03

Forward all incoming email to single address

AddThis Social Bookmark Button

Ubuntu Postfix to forward all incoming email to single address

Forward All incoming Email to single address

Sometimes you don't want to create specific address for specific web site on a server but you want to redirect all incoming messages to a single address. In this tutorial we will explain how to achieve it using Postfix on a Ubuntu Server.

In our example we want to redirect the email info@mydomain.com to myemail@gmail.com

1) Install postfix

ubuntu install postfix shell command

sudo apt-get install postfix

During the installation process, the package manager will prompt you for the responses to a few questions. To the first question regarding the type of mail server you want to configure select "No configuration" and continue as in the following image:

Postfix package configuration

Choose : no configuration

Copy the proposed main.cf configuration file

ubuntu install postfix shell command

cp /usr/share/postfix/main.cf.debian /etc/postfix/main.cf

2) Setup catch-all email account

Edit your mapping file by executing the following command

Edit postfix mapping configuration file

vi /etc/postfix/virtual

Append the following line in the virtual configuration file .

postfix virtual mapping Configuration

@mydomain.com myemail@gmail.com

Save and close the file

3) Post your Mapping

Postmap is utility program that will convert /etc/postfix/virtual to /etc/postfix/virtual.db in Berkley DB format, so that Postfix can access the data faster. We will execute postmap on our newly created virtual mapping. It will rebuild our the virtual alias database

Postmap execution

postmap /etc/postfix/virtual

4) Check

Make sure you have the following line in the /etc/postfix/main.cf. If you don't have it feel free to add them.

postfix main.cf

virtual_alias_domains = mydomain.com
virtual_alias_maps = hash:/etc/postfix/virtual
myhostname = mydomain.com
Line 1 The virtual_alias_domains setting tells Postfix that mydomain.com is a so-called virtual alias domain. If you omit this setting then Postfix will reject mail (relay access denied) or will not be able to deliver it (mail for mydomain.com loops back to myself). Never list a virtual alias domain name as a mydestination domain!
Line 2 The /etc/postfix/virtual file contains the virtual aliases.Mail for all other addresses in mydomain.com is rejected with the error message "User unknown" .

Postfix configuration main.cf file

The Postfix main.cf configuration file specifies a very small subset of all the parameters that control the operation of the Postfix mail system. Parameters not explicitly specified are left at their default values.

5) Restart postfix

sudo service postfix restart


/etc/init.d/postfix reload

6) Test your configuration

Postfix logs all failed and successful deliveries to a logfile. The file is usually called /var/log/maillog or /var/log/mail; the exact pathname is defined in the /etc/syslog.conf file.

On Ubuntu Postfix sends all log messages to /var/log/mail.log . However error and warning messages can sometimes get lost in the normal log output so they are also logged to /var/log/mail.err and /var/log/mail.warn respectively.

Postfix test forwarding

When you test Postfix forwarding, don't send the test email from the destination address !!!

I am forwarding mail on mydomain.com to my gmail account, but I was testing my setup by sending an email from my gmail account (and expecting it to come back as a forward). THAT WON'T WORK. Test by sending mail from another account.

To see messages entered into the logs in real time you can use the tail -f command:

Log verification

tail -f /var/log/mail.err

If you are having trouble sending or receiving mail from a specific domain you can add the domain to the debug_peer_list parameter.

sudo postconf -e 'debug_peer_list = mydomain.com'
Tags: install , specific , ubuntu , single , email , postfix , address , incoming , achieve

Add comment

Security code

Java Tutorial on Facebook