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.

Prerequisites

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 linuxaria.com I would use:

dig linuxaria.com mx
;  DiG 9.8.1-P1  linuxaria.com 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
 
;; QUESTION SECTION:
;linuxaria.com.			IN	MX
 
;; ANSWER SECTION:
linuxaria.com.		300	IN	MX	1 mail.linuxaria.com.

And the result should be something like mail.yourdomain.com 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/main.cf with your favorite editor and add these 2 lines:

virtual_alias_domains = linuxaria.com
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:

user1@linuxaria.com  linuxaria@gmail.com

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 account@domain 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]

@linuxaria.com   linuxaria@gmail.com

Conclusions

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!

  10 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! )

    • 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/main.cf

  4. Thank you very much, I finished it in just 5 minutes :)

  5. 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 mail.murrayvalleybushwalkers.org.au – 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
    regards
    Tony Marsh

    ; <> DiG 9.9.5-3-Ubuntu <> murrayvalleybushwalkers.org.au 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

    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 512
    ;; QUESTION SECTION:
    ;murrayvalleybushwalkers.org.au. IN MX

    ;; ANSWER SECTION:
    murrayvalleybushwalkers.org.au. 1799 IN MX 1 mail.murrayvalleybushwalkers.org.au.

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

  6. 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 mail.murrayvalleybushwalkers.org.au still fails
    Perhaps propagation of the MX record takes time although I created the record 12 hours ago
    Tony

  7. 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
    here
    Now just got to get forwarding working
    Tony

 Leave a Reply

(required)

(required)


*

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=""> <strike> <strong>