22

I am trying to set up mail forwarding on a new server of mine. For example, I want emailaddress@mydomain.com to forward all email sent to it to, say, otheremail@gmail.com. I do not need/want to be able to send mail from mydomain.

I'm running Ubuntu 10.04 and it's my server so I have root access and can install/modify anything necessary. I have a few years of Linux experience, but never played with mail servers before so I literally know nothing about them. Hence, I can't really understand all the questions that have been previously asked about this topic. There also seems to be many different answers given and it would take forever to read about every solution proposed. That being said, can anyone point me in the right direction on how to accomplish this? Thank you!

shanet
  • 355
  • 1
  • 3
  • 7

3 Answers3

21

I prefer postfix, it's easier to configure and by default, most things are turned off:

  1. Install postfix.
  2. In /etc/postfix/main.cf set these two options

    mydomain = example.com
    mydestination = example.com
    

    Replace "example.com" with your actual domain. This is very important

  3. Optionally in main.cf, set myhostname to something appropriate (could also be "example.com")
  4. Add this line somewhere in main.cf:

    local_transport = error:local delivery is disabled
    

    this turns off local transport so email delivery to local users are turned off (you can skip this is you want local users to receive email).

  5. In main.cf, make sure you have this line (there should be lots of variations that have been commented out):

    alias_maps = hash:/etc/aliases # (or `hash:/etc/mail/aliases`, etc.)
    
  6. Now edit the /etc/aliases (or /etc/mail/aliases or whatever it was in main.cf) and create the alias: emailaddress: otheremail@gmail.com, this will make it so incoming email for "emailaddress@example.com" get forwarded to "otheremail@gmail.com"

  7. Save main.cf and run this command: postalias /etc/aliases (or /etc/mail/aliases or whatever it was in main.cf).
  8. Start postfix: sudo /etc/init.d/postfix start

Here is some more info for postfix on ubuntu: https://help.ubuntu.com/community/Postfix

masegaloeh
  • 17,978
  • 9
  • 56
  • 104
Jon Lin
  • 1,343
  • 9
  • 21
  • Sounds pretty easy as well. I will update once my DNS admin getting the MX record needed. – shanet Nov 08 '11 at 06:09
  • 2
    Yeah, I forgot to mention that you need to point your domain's MX record to this server. – Jon Lin Nov 08 '11 at 06:14
  • After failing to get sendmail working correctly, I tried using Postfix with your directions. It's working beautifully now. Thank you! – shanet Nov 09 '11 at 01:37
  • 1
    I'm getting ```Recipient address rejected: local delivery is disabled``` – Oliver Dixon Feb 01 '16 at 17:46
  • @OliverDixon me too. – Laizer Jan 01 '18 at 21:29
  • What if there are several domains all pointing at this server via virtual hosts? How should the instructions be modified if `info@mydomain1.com` and `info@mydomain2.com` both need to be forwarded? – osullic May 19 '18 at 20:43
  • @osullic you'll need to add the additional domains to the mydomains/mydestination lines, examples: http://www.postfix.org/BASIC_CONFIGURATION_README.html#mydestination – Jon Lin May 21 '18 at 18:31
4

Do you already have a functioning incoming mail server? Have you setup MX records for you domain yet?

  • Set up mx records in DNS
  • Install sendmail

Set up /etc/mail/virtusertable with the following forwarding line:

emailaddress@mydomain.com   otheremail@gmail.com
Andrew Case
  • 3,409
  • 3
  • 21
  • 38
  • That simple huh? I contacted my DNS admin about adding the MX record and already have sendmail installed. Hopefully the MX record will be added tomorrow and I'll update then. – shanet Nov 08 '11 at 04:52
  • I decided to try this method. It wasn't "that simple". But it's pretty straightforward - just a few steps to go through. I posted the steps as an [answer to my own question](https://serverfault.com/a/914930) - which seems to be the same as this one. – osullic Jun 02 '18 at 20:57
0

I followed the advice from @jon-lin, and got stuck with mail bouncing back with a Recipient address rejected: local delivery is disabled message. I found that setting up virtual alias maps worked.

  1. Install postfix.

  2. Add these lines to main.cf:

    virtual_alias_domains = mydomain.com myanotherdomain.com

    virtual_alias_maps = hash:/etc/postfix/virtual

  3. Set up /etc/postfix/virtual as follows:

    contact@mydomain.com myself@gmail.com

    sales@mydomain.com myself@gmail.com

    The first email is the address on which postfix shall receive emails, and the second is the address where postfix would forward the emails. Notice that the format here is different than the alias file - it is space separated.

  4. Run postmap /etc/postfix/virtual

  5. Reload postfix config with sudo /etc/init.d/postfix reload

See this guide for reference: http://www.binarytides.com/postfix-mail-forwarding-debian/

Laizer
  • 158
  • 7