Solved

CentOS:  Setup email server and configure email forwarders

Posted on 2011-03-13
62
966 Views
Last Modified: 2013-11-08
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.
0
Comment
Question by:detox1978
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 32
  • 28
  • +1
62 Comments
 
LVL 78

Expert Comment

by:arnold
ID: 35123679
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

0
 
LVL 31

Expert Comment

by:farzanj
ID: 35123953
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.
0
 
LVL 2

Author Comment

by:detox1978
ID: 35124532
I've installed webmin and postfix, but cant see the option for email forwarding.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 31

Expert Comment

by:farzanj
ID: 35124555
Try editing /etc/postfix/virtusertable

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

Depends upon your specifics
0
 
LVL 2

Author Comment

by:detox1978
ID: 35125263
that file doesn't exist, but the folder does, should i create it?

Also, what is the syntax for a catch all?
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35125301
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.
0
 
LVL 2

Author Comment

by:detox1978
ID: 35125312
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.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35125320
By above, I meant

@abc.com             %1@def.com


Try this:
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35125356
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 35125769
0
 
LVL 2

Author Comment

by:detox1978
ID: 35128916
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.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35128985
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.
0
 
LVL 2

Author Comment

by:detox1978
ID: 35129723
Can you give me a sample of what to write in  /etc/postfix/main.cf to setup virtual_alias_maps
0
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
ID: 35130179
Two lines go in /etc/postfix/main.cf

virtual_alias_domains = mydomain.com                           <---- Change this domain name for your own
virtual_alias_maps = hash:/etc/postfix/virtual

Then open /etc/postfix/virtual

And enter
@mydomain.com             %1@anotherdomain.com
0
 
LVL 2

Author Comment

by:detox1978
ID: 35131514
Thanks,

what about directing single addresses?
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35131618
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
0
 
LVL 2

Author Comment

by:detox1978
ID: 35132387
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.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35132538
Can you generally email from hostA to hostB and receive it without a trouble?
0
 
LVL 2

Author Comment

by:detox1978
ID: 35133606
I've only just installed it.

How do i test?
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35133651
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)
0
 
LVL 2

Author Comment

by:detox1978
ID: 35133735
no email arrived with test 1
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35133752
So, your server is simply not working.  So we cannot blame forwarding yet

Now use email address with IP addresses NOT with domain name.
0
 
LVL 2

Author Comment

by:detox1978
ID: 35133814
I want to forward to a yahoo account, so i dont know about Ip addresses.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35133826
Are you sending email from Yahoo also?

Can you do this successfully: nslookup mail.yahoo.com
0
 
LVL 2

Author Comment

by:detox1978
ID: 35133856
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
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35133889
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.
0
 
LVL 2

Author Comment

by:detox1978
ID: 35133947
Yeah i have a domain that i am forwarding.  I've created an MX record mail.mydomain.com

0
 
LVL 31

Expert Comment

by:farzanj
ID: 35134007
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.  
0
 
LVL 2

Author Comment

by:detox1978
ID: 35134058
yes i can do an nslookup against my domain name.  I can also see the correct MX record via http://www.mxtoolbox.com/
0
 
LVL 2

Author Comment

by:detox1978
ID: 35134169
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
0
 
LVL 2

Author Comment

by:detox1978
ID: 35134174
Also i can't telnet to port 25
0
 
LVL 2

Author Comment

by:detox1978
ID: 35134194
This is a VPS i hire in a data center, so port 25 will be open on the firewall.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35134213
Ok.  Open it.

Do you know the entire SMTP protocol so that you can use it to do an email by using telnet
0
 
LVL 2

Author Comment

by:detox1978
ID: 35134221
yes i know how to send an email using telnet.

How do check if the port is open?
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35134244
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
0
 
LVL 2

Author Comment

by:detox1978
ID: 35134263
-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?
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35134281
So, the service is running at least
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35134290
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
0
 
LVL 2

Author Comment

by:detox1978
ID: 35134297
sounds like a good plan.

how do i edit the config file?
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35134344
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
0
 
LVL 2

Author Comment

by:detox1978
ID: 35134408
I can now telnet to port 25, but can't forward email;
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35134428
Do you receive emails now?
0
 
LVL 2

Author Comment

by:detox1978
ID: 35134488
no nothing being forwarded.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35134601
no. do you get it at least.  not asking about forwarding yet.
0
 
LVL 2

Author Comment

by:detox1978
ID: 35134657
I can see the emails in the webmin queue.

However an SMTP test on http://www.mxtoolbox.com results in a timeout.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35134698
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.

0
 
LVL 31

Expert Comment

by:farzanj
ID: 35134704
Use a local system and use IP addresses, to avoid any problem with DNS.
0
 
LVL 2

Author Comment

by:detox1978
ID: 35134748
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.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35134761
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.  
0
 
LVL 2

Author Comment

by:detox1978
ID: 35134796
I'm only interested in the forwarders.

If you could walk me through those steps.
0
 
LVL 2

Author Comment

by:detox1978
ID: 35134801
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.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35134822
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
0
 
LVL 2

Author Comment

by:detox1978
ID: 35135078
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.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35136683
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?
0
 
LVL 2

Author Comment

by:detox1978
ID: 35138417
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?

0
 
LVL 2

Author Comment

by:detox1978
ID: 35141752
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]
0
 
LVL 2

Author Comment

by:detox1978
ID: 35141841
Does this mean the server is unable to forward the message?
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35142272
Yes, it should be enabled.
0
 
LVL 2

Author Comment

by:detox1978
ID: 35142940
How do I check/enable?
0
 
LVL 2

Author Closing Comment

by:detox1978
ID: 35144217
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.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35146155
I am glad it turned out good.

Did this kind of forwarding work too?
@mydomain.com             %1@anotherdomain.com
0
 
LVL 2

Author Comment

by:detox1978
ID: 35171316
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
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question