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!

  7 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 myvps.be 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: http://pastebin.com/raw.php?i=qQbKx2UL
    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/main.cf

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

 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>