22

I am trying to set up mail forwarding on a new server of mine. For example, I want [email protected] to forward all email sent to it to, say, [email protected]. 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!

3 Answers 3

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: [email protected], this will make it so incoming email for "[email protected]" get forwarded to "[email protected]"

  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

7
  • Sounds pretty easy as well. I will update once my DNS admin getting the MX record needed.
    – shanet
    Nov 8, 2011 at 6:09
  • 2
    Yeah, I forgot to mention that you need to point your domain's MX record to this server.
    – Jon Lin
    Nov 8, 2011 at 6:14
  • After failing to get sendmail working correctly, I tried using Postfix with your directions. It's working beautifully now. Thank you!
    – shanet
    Nov 9, 2011 at 1:37
  • 1
    I'm getting Recipient address rejected: local delivery is disabled Feb 1, 2016 at 17:46
  • @OliverDixon me too.
    – Laizer
    Jan 1, 2018 at 21:29
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:

[email protected]   [email protected]
2
  • 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 8, 2011 at 4: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 - which seems to be the same as this one.
    – osullic
    Jun 2, 2018 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:

    [email protected] [email protected]

    [email protected] [email protected]

    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/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .