Dec 152012

Since its initial introduction into the business world in 2005, Google Apps has been available to small business users for free. Even when the premium version was launched in 2007, Google still maintained a free standard version for individuals and small organizations, this was great for small website, they could have their emails managed by the Big G.

But as you can read from the official blog this has come to an end:

For Businesses, instead of two versions, there will be one. Companies of all sizes will sign up for our premium version, Google Apps for Business, which includes 24/7 phone support for any issue, a 25GB inbox, and a 99.9% uptime guarantee with no scheduled downtime. Pricing is still $50 per user, per year.

This is not doable for small websites that have their own domain but don’t need this service for 50$, so a good solution in these cases is to set up on your VPS a postfix server that can forward all the emails to another email.

In the following example I’ll use the email [email protected] as email that i want to forward away and [email protected] as email that will receive all the emails.


Before you can start to do this setup you just need to verify 2 things:

1) You need to have postfix installed, this can be easily achieved with the command:

sudo apt-get install postfix

2) The MX record of the domain you want to forward must be set to the vps with postfix installed, to check this you can use the command dig with the option MX, so to check the domain I would use:

dig mx
;  DiG 9.8.1-P1 mx
;; global options: +cmd
;; Got answer:
;; HEADER opcode: QUERY, status: NOERROR, id: 16783
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0
;			IN	MX

And the result should be something like that is a cname record to your VPS.

Postfix Mail Forwarding Domains

This configuration is useful if you do not have local mailboxes and just want to use postfix to forward email to somewhere, to do this edit the file /etc/postfix/ with your favorite editor and add these 2 lines:

virtual_alias_domains =
virtual_alias_maps = hash:/etc/postfix/virtual

This is the goal of these 2 directive:

virtual_alias_domains = Postfix is final destination for the specified list of virtual alias domains, that is, domains for which all addresses are aliased to addresses in other local or remote domains.

virtual_alias_maps = Optional lookup tables that alias specific mail addresses or domains to other local or remote address

Now create the file /etc/postfix/virtual and put in it this line:

Save and reload postfix with these 2 commands:

postmap /etc/postfix/virtual
/etc/init.d/postfix reload

All it’s done !
Just send an email to the mail forwarding [email protected] and you should receive immediately the email to your other account.
If you have any problem just check the log located in /var/log/mail.log

Catch ’em all

You can also implement a catch-all address for the whole domain so all email sent to [email protected] will be forwarded to [email protected]


This is just a quick and dirty guide to setup in 15 minutes (and probably less) some forward emails to your real email, I hope that this can help you, like it helped me.

Popular Posts:

Flattr this!

  11 Responses to “How to setup postfix to forward email to another email account on Debian/Ubuntu”

  1. Very glad I subscribed to the rss here lol, VERY helpful and useful tip. Very thankful for this.

  2. Followed the instruction exactly and this doesn’t work..

    Remote host said: 550 #5.1.0 Address rejected. [RCPT_TO]

    There’s an instruction missing here.

    • Hello Tim,
      These instructions worked for me.
      In this case I see that the host has rejected your message, this could be a problem of that particular email (or MX).

      Without the forwarding everything works fine ?

  3. Awesome! Thank you very much! It works! )

  4. Hi,
    thank you for this nice tutorial. I have been able to set up postfix, but the mails don’t go through.
    I have made a catch all for my domain to my email address. I am trying to send mails to [email protected] but they don’t appear in my mailbox.

    This is the log I get when I send a mail:
    I have replaced my own email address with ***MYMAIL*** for security reasons.

    • Jeroen: you seem to be connecting to gmail using an IPv6 address. Make sure IP6 is working on the box, or use IP4 by adding inet_protocols=ipv4 to your /etc/postfix/

  5. Thank you very much, I finished it in just 5 minutes 🙂

  6. Thank you for the excellent tutorial – have followed it closely and believe I have the right MX record in place (as reproduced below). However I cannot ping – so when I send an email to do one of the addresses I want to forward to gmail it fails to send.
    Any suggestions greatly appreciated
    Tony Marsh

    ; <> DiG 9.9.5-3-Ubuntu <> mx
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39031
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

    ; EDNS: version: 0, flags:; udp: 512
    ; IN MX

    ;; ANSWER SECTION: 1799 IN MX 1

    ;; Query time: 348 msec
    ;; SERVER:
    ;; WHEN: Sun Aug 10 19:29:22 EDT 2014
    ;; MSG SIZE rcvd: 80

  7. It turns out I still had sendmail service running – have since stopped that and reinstalled Postfix
    sudo apt-get install –reinstall postfix
    sudo postfix status
    postfix/postfix-script: the Postfix mail system is running: PID: 4171
    However ping of still fails
    Perhaps propagation of the MX record takes time although I created the record 12 hours ago

  8. Well Ive resolved the problem with the mail server – it was the improperly formed dns A and MX record – I can now ping the mail server
    Thanks to Kamal on April 14 2014 response
    Now just got to get forwarding working

  9. worked like a charm! thanks man, saved me few hours of MX server setup 🙂

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>