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!
I prefer postfix, it's easier to configure and by default, most things are turned off:
In /etc/postfix/main.cf set these two options
Replace "example.com" with your actual domain. This is very important
myhostname
to something appropriate (could also be "example.com")Add this line somewhere in main.cf:
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).
In main.cf, make sure you have this line (there should be lots of variations that have been commented out):
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]"postalias /etc/aliases
(or/etc/mail/aliases
or whatever it was in main.cf).sudo /etc/init.d/postfix start
Here is some more info for postfix on ubuntu: https://help.ubuntu.com/community/Postfix
Do you already have a functioning incoming mail server? Have you setup MX records for you domain yet?
Set up
/etc/mail/virtusertable
with the following forwarding line: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.
Install postfix.
Add these lines to main.cf:
virtual_alias_domains = mydomain.com myanotherdomain.com
virtual_alias_maps = hash:/etc/postfix/virtual
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.
Run
postmap /etc/postfix/virtual
sudo /etc/init.d/postfix reload
See this guide for reference: http://www.binarytides.com/postfix-mail-forwarding-debian/