Link to home
Start Free TrialLog in
Avatar of detox1978
detox1978Flag for United Kingdom of Great Britain and Northern Ireland

asked on

CentOS: Setup email server and configure email forwarders

Hi All,

I have a CentOS VPS and would like to setup email forwarding.


The server has YUM setup and i have root SSH access.
Avatar of arnold
arnold
Flag of United States of America image

yum install postfix #mailserver
yum install webmin #web GUI based system administration tool.
Or Download from http://www.webmin.com/download.html the most current version

You can configure one of sendmail or postfix.

Here are the instructions if you want to  configure sendmail.

http://www.wikihow.com/Configure-Sendmail

For mail forwarding, you can do it at both server or client level.

For server level mail forwarding after installing sendmail server, you would need to edit a few entries in the /etc/mail/virtusertable.  With entries in this table you can forward mail in the most flexible way.
For example, you can do this:

@abc.com             %1@def.com

The above would forward all emails of a domain to their counterpart on the other domain.  Or you can forward to another user.

For client level forwarding, you need to create a ".forward" file the the home directory of the forwarding user and write a comma separated list of emails where the user wishes to forward it.
Avatar of detox1978

ASKER

I've installed webmin and postfix, but cant see the option for email forwarding.
Try editing /etc/postfix/virtusertable

And enter the following
username@somedomain.dom realuser@someotherdomain.dom

Depends upon your specifics
that file doesn't exist, but the folder does, should i create it?

Also, what is the syntax for a catch all?
In your /etc/postfix/main.cf file, check the virtual_alias_maps

grep "virtual_alias_maps" /etc/postfix/main.cf


It should tell you the name of the file where you should put forwarding information.

For syntax, you should be able to do "man" on it.

Try the syntax I gave you above.
It looks like there is no entry;


-bash-3.2# grep "virtual_alias_maps" /etc/postfix/main.cf
#   /etc/passwd, /etc/aliases, or the $virtual_alias_maps files.
By above, I meant

@abc.com             %1@def.com


Try this:
farzani, i couldn't find any virtual alias reference, but did find;

alias_maps = hash:/etc/aliases



insoftservice, I dont have access to the GUI that link requires, just SSH.
Is it something that you satisfies your requirements?

http://www.cyberciti.biz/tips/how-to-redirect-one-users-mail-to-another-user-with-postfix.html

Otherwise, just create virtual_alias_maps in your config file which should not be terribly hard.
Can you give me a sample of what to write in  /etc/postfix/main.cf to setup virtual_alias_maps
ASKER CERTIFIED SOLUTION
Avatar of farzanj
farzanj
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks,

what about directing single addresses?
Just write single addresses

First column is from:  second column is to
One to one
sender@gmail.com            receiver@yahoo.com

Many to one (all of mydomain)
@mydomain.com              admin@anotherdomain.com
I've add the follow;

#  vi /etc/postfix/main.cf

virtual_alias_domains = mydomain.com
virtual_alias_maps = hash:/etc/postfix/virtual

#  vi /etc/postfix/virtual
@mydomain.com              myemail@yahoo.com


restarted the service and sent myself an email, but nothing has come through.
Can you generally email from hostA to hostB and receive it without a trouble?
I've only just installed it.

How do i test?
Test 1:

Send mail using command line utilities.

echo "this is a test message" | mail -s "test1" email@targetdomain.com


Test 2:
A: Where you configured your server and want it to forward.
B: Where you want to receive it

On A: user --> is the user who receives email.  And forwarding address is email@targetdomain.com

Then
echo 'email@targetdomain.com' > ~user/.forward

Now send email to user@domain.com (On A)
no email arrived with test 1
So, your server is simply not working.  So we cannot blame forwarding yet

Now use email address with IP addresses NOT with domain name.
I want to forward to a yahoo account, so i dont know about Ip addresses.
Are you sending email from Yahoo also?

Can you do this successfully: nslookup mail.yahoo.com
i'm logging into the yahoo webmail and sending an email to test@mydomain.com, the forwarder should forward it to my other Yahoo account
Do you have a registered domain name?  And, do you have a live IP address?  If you don't know what I am talking about then you don't have it.

In general it is a bad idea to test it this way.  You should have at least two computers in your local network or connected together NIC to NIC.  If you cannot do that, then make three email accounts from one computer to another and see if forwarding and mailing works.   It can be tested in one single machine.
Yeah i have a domain that i am forwarding.  I've created an MX record mail.mydomain.com

I don't think we are on the same page.

Can any one in the world do nslookup on your server and would get your IP? Is it a public IP address?  The IP address must be registered with some service provider.  You cannot do it yourself.

Just test within your home network, please.  
yes i can do an nslookup against my domain name.  I can also see the correct MX record via http://www.mxtoolbox.com/
I run the SMTP test on http://www.mxtoolbox.com/ and it returned

No connection could be made because the target machine actively refused it myip:25
Also i can't telnet to port 25
This is a VPS i hire in a data center, so port 25 will be open on the firewall.
Ok.  Open it.

Do you know the entire SMTP protocol so that you can use it to do an email by using telnet
yes i know how to send an email using telnet.

How do check if the port is open?
telnet shows you can reach it or not.

netstat shows it is even advertised or not

so you can do:

netstat -antp | grep 25

So see if it is even announced.

If it is announced, it is not the fault of postfix.  If it is not announced then, there is something wrong with postfix
-bash-3.2# netstat -antp | grep 25
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      19073/master



Should the external IP address be in that list?
So, the service is running at least
There is a  problem:  It is not getting announced on your IP address.  It is only getting advertised on loopback.  This is a problem.
You will have to modify your config file and restart it.  Then show me if the service advertises on correct IP
sounds like a good plan.

how do i edit the config file?
in /etc/postfix/main.cf

Find:
inet_interfaces

It may be commented

So, set it to your IP address (of the server) the live IP.

inet_interfaces = <IP-ADDR>

service postfix restart

netstat -tulpn | grep master
I can now telnet to port 25, but can't forward email;
Do you receive emails now?
no nothing being forwarded.
no. do you get it at least.  not asking about forwarding yet.
I can see the emails in the webmin queue.

However an SMTP test on http://www.mxtoolbox.com results in a timeout.
It must be in the queue for sending it out on the machine that you used to send it out.  I think it is not sending/receiving.

You should always try simple things first.  A local system should be used to test one service at a time to avoid time wastage in trouble shooting.

Use a local system and use IP addresses, to avoid any problem with DNS.
This is a VPS in a datacenter, so i only have access to the one server.  I think the email may be from the manual SSH tests we sent.
Make three account on the same server and try sending emails.

Email will be tested.  Forwarding will be surely tested.  First account the sendor, second the forwarder, and third the receiver.  
I'm only interested in the forwarders.

If you could walk me through those steps.
I've just looked at the queue again and none of the emails i sent have been recieved.  they are all the ones i manually created on the server.
I knew that.  You have way too may troubles on the server.  DNS not fully configured.  Firewall status unknown and who knows what else.

The easy way to test.

create three users
test1: useradd test1
test2: useradd test2
test3: useradd test3
passwd test1
passwd test2
passwd test3

TEST1:
In /etc/postfix/virtual
test2@localhost        test3@localhost

SAVE

su - test1
echo "test message" | mail -s "From 1 to 2" test2@localhost

exit
su - test3

mail

See if you received anything
The DNS is working fine.


I removed the catch all forwarder and the manual tests now work;

echo "this is a test message" | mail -s "test1" email@targetdomain.com


Also the SMTP check now works with at http://www.mxtoolbox.com/


So i must have made a typo.
Well, DNS don't have an MX record.  At least it did not show up for me.

Is forwarding working among users on the same machine?
I've not posted my domain, as i'm a novice and didn't want to advertise an easy target.  The MX records show up wheni query the domain on http://www.mxtoolbox.com/ and it passes there SMTP test.  But this was only after i took the forwarding off.

Are there any PHP script that can be used to manage forwarding?

ok, I've had another go at setting up a single email forwarder (not a catch all).

I mssage was bounced with the following error;

Remote host said: 554 5.7.1 <test@mydomain.com>: Relay access denied [RCPT_TO]
Does this mean the server is unable to forward the message?
Yes, it should be enabled.
How do I check/enable?
Got it working in the end.  not sure what i was doing wrong, but deleted all the changes and readded them and now it works.
I am glad it turned out good.

Did this kind of forwarding work too?
@mydomain.com             %1@anotherdomain.com
The bit i was missing is the virtual.db, which holds the forwarder information needs to be reloaded after a change is made to virtual file.

#cd /etc/postfix/
#postmap virtual