Help needed with internal mail routing

CyberStorm

Well-Known Member
Joined
Feb 10, 2006
Messages
128
Reaction score
18
Location
Durban, South Africa
I'm hoping for some advice on the following situation I find myself in:

I'm setting up a website for a company. They have chosen a new domain for their corporate website. The hosting account that I have chosen provides me with around 35 POP3 mailboxes for email. I have full control over them via a web console. So far so good!

This company currently has a capped 10 GB ADSL account.

They also send huge attachments and documents to each other within the company via a Postfix mail server located on site. This internal mail does not go out of the company and therefore does not eat up the 10 GB cap! Moving on...

They currently have a domain which they feel does not properly represent their company at large. This is the reason for the new domain.

I am concerned that because of the POP3 mail access the 'internal' mail will go out through the ADSL router to the hosting company's POP3 server and then make a round trip back to this company's network. All the while wasting bandwidth!!

Is there any for me to prevent internal mail from leaving the router and not chew up bandwidth?

I just want this routed internally so as to save the cap as much as possible.

If it means using Sendmail or re-configuring Postfix or even Exchange then so be it! Any and all solutions will be more than welcomed!!

Any help on this would be very greatly appreciated. Thanks guys...
 
Last edited:
Let me check if I understand this correctly. Your postfix box downloads the mail from the ISP's pop3 server and drops it in local mailboxes?

Does your postfix box accept mail for the current domain? I.e. if you set your outgoing server to be the postfix box, and you send mail to an address on the current domain, does it get delivered *on* the postfix box?

I know postfix pretty well, can help you with this - you don't need anything else.
 
That's correct. The company uses Outlook Express. Outgoing mailserver address (SMTP) is set the IP address of the postfix mail server on the local LAN.

Mail sent from between users in the same domain gets routed via the postfix mail server and does not leave the local LAN!

A new domain will be registered. I will create POP3 accounts using an internet admin console.
The hosting company will provide me with a POP3 and SMTP address as well as user-names and passwords for each account I create.

I want to point the clients (Outlook Express) to the local postfix server that will keep internal mail within the local LAN. The postfix server must pull POP3 mail for all users and deliver to the appropriate user.

Can this be done??
 
just setup a virtual host on your linux server for the newdomainname.co.za

then u have more than one domain on that linux server pc. the mail server wont have a public ip/resolved dns name, so dont worry about new domain

im not a linux guru, but our network admin, configured quite a few clients for me

i prefer exchange 2003, more of a windows guy

but yes, it is possible. read on google about virtual hosts. we have centos loaded on our mailserver, and with postfix.admin you can add virutal hosts/domains

you can even setup a internal domain, like @cyber.local
 
@ Aqox: But how would the linux box need to be set up to forward all non-local to the ISP's SMTP server?

Also, what sort of config would required in postfix or otherwise to allow the mail server to receive mail from the ISP's POP3 server?

With regard to exchange, all non local mail would be sent using the SMTP connector?
 
CyberStorm,

What distro are you running? Look in /etc/postfix/ there should be two files:

mydomains

and

virtual

mydomains should look like this:

Code:
localhost                      OK
servername.localdomain.tld     OK   
domain1.co.za                  OK
cooldomain.co.za               OK

This tells Postfix that these domains should be treated as local.

The virtual file maps e-mail addresses to local users. What makes this nice is that you can link two e-mail addresses to one user, so the user only has to collect mail from one account.

Code:
[email protected]        cyberstorm
[email protected]     cyberstorm
[email protected]      koffiejunkie
[email protected]   koffiejunkie

Once you edited these two files, you have to creat the .db files that Postfix will read:

postmap hash:/etc/postfix/mydomains
postmap hash:/etc/postfix/virtual

Then, in /etc/postfix/main.cf you have to make two changes.

You probably have something like this:

mydestination = domain.co.za, localhost

change this to

mydestination =

And add these two:

virtual_mailbox_domains = hash:/etc/postfix/mydomains
virtual_mailbox_maps = hash:/etc/postfix/virtual

Restart postfix and all should be good. Let me know if it doesn't work. I'm writing from memory now, so I might make mistakes - will fix it on sunday (when I have access to one of the boxes I set up like this).

The postfix.admin that Aqox referred to is a very elegant solution, but on some distros it's tricky to install, because the RH based distros, for example, don't build Postfix with MySQL support. I don't even want to talk about Mandrake/Mandriva. The other problem with this is that using a MySQL backend puts more load on the server. Mostly not a problem, but if it's a busy box, especially if a lot of it's work is disc-bound, you might run into problems. Depends on the traffic volume and hardware. Up to you though.
 
Thanks you very much for this koffeejunkie!! It is much appreciated!!

The mail server is running Fedora Core 1.

So if my assumption is correct, this should take care of internal mail rotuing and all mail sent between users in the same domain will not leave the local LAN.

So my next question would be, how would I setup postfix to fetch POP3 mail from the POP3 mail server address provided by the ISP?

Also how would I need to configure postfix to send external mail to the SMTP server address provided by the ISP?

Would I be able to use a command like fetchmail to tell the mail server to automatically pull the POP3 server every few minutes for example?
 
Hello Cyberstorm.

To configure postfix to send external mail via the ISP's SMTP server, you need this in main.cf:

relayhost = isp.mail.server

Postfix is just a MTA, it doesn't fetch. For that you need fetchmail. How you configure fetchmail depends on one thing: do you have a global pop box (i.e. all the mail for your domain goes into one mailbox) or does each user has his/her own mailbox at the ISP?

If users each have their own mailbox at the ISP it's easy. In /etc/fetchmailrc each have a line like this:

poll "isp.mail.server" protocol POP3 auth password : user "username_at_isp" there with password "password_at_isp" is "local_username" here;

If it is a global box I'm not entirely sure, haven't done it in ages, I think "local_username" becomes just * but you'll have to look it up.

Before you configure this, send a test mail from the command line (assuming 'cyberstorm' is a local user):

mail -s test cyberstorm

Look in you mail log - it will be translated into cyberstorm@something - something being localhost or localhost.localdomain or localhost.your_server_name or just your_server_name. You need to make sure that Postfix knows to accept mail for this "domain" otherwise it will try to send the mail out. If you make "local_username" a complete valid e-mail address, it should work. Otherwise add the domain to the mydestination setting (instead of in the mydomains file). Domains in mydestination automatically accept mail for any local user.
 
Hi koffeejunkie,

Each user has their own POP3 mailbox. This should make things somewhat easier for me according to your very helpful post. :)

I have virtual machines currently setup for give this a dry run. I am very eager to test out this solution, and will be sure to report back my experience to you.

I must take this chance to thank you again for all the time you've taken to type out these longs posts. I really appreciate it. :)

CyberStorm
 
koffeejunkie: my postfix directory does not have a mydomains file. It does however have virtual and main.cf files!

Is the mydomains file version specific?I'm running postfix 2.2.5.5
 
Thanks will do.

I have performed the commands below:

postmap hash:/etc/postfix/mydomains
postmap hash:/etc/postfix/virtual

Next I go to /etc/postfix/main.cf and make these changes:

mydestination = domain.co.za, localhost

change this to

mydestination =

And add these two:

virtual_mailbox_domains = hash:/etc/postfix/mydomains
virtual_mailbox_maps = hash:/etc/postfix/virtual

Am I right in assuming, that mydestination = domain.co.za, localhost (the domaind.co.za and localhosts parts will be removed and replaced with

mydestination =
virtual_mailbox_domains = hash:/etc/postfix/mydomains
virtual_mailbox_maps = hash:/etc/postfix/virtual
 
You can put hash:/etc/postfix/mydomains in either mydestination = or virtual_mailbox_domains = depending on what else you're trying to do - both should work.
 
That said, if it's just two domains, and they'll have the same mailboxes, you can also just use:

mydestination = domain1.co.za, domain2.co.za, localhost

and be done with it. Putting it in a file becomes more usefull when the domains have different mailboxes.
 
@koffeejunkie:

No luck I'm afraid. I tried setting up my test system with just one domain. I have two gmail accounts and since gmail provides pop3 access I thought it would be the perfect dry run to test out my postfix config.

I did exactly as your posts. I'm stumped.

I created the mydomains file like so:

Code:
localhost                             OK
linux.local.lan                       OK   
gmail.com                            OK


I setup virtual as:

Code:
[email protected]            cyberstorm1
[email protected]            cyberstorm2

I then ran the following commands:

Code:
postmap hash:/etc/postfix/mydomains
postmap hash:/etc/postfix/virtual

The ran successfully with no reported error messages.

Then in/etc/postfix/main.cf I set the following:

Code:
mydestination = gmail.com, localhost

I also added these after mydestination:

Code:
virtual_mailbox_domains = hash:/etc/postfix/mydomains
virtual_mailbox_maps = hash:/etc/postfix/virtual

I then restarted postfix. That went fine.

I then setup Outlook Express in Windows XP on the same LAN (I can ping the linux box and the linux box can ping the XP PC). My POP and SMTP server is the IP of the linux box, I specified the username and password of the user account I created (in this case: cyberstorm1)

After clicking Send/Receive, Outlook Express tried to connect to the linux box but it just times out!!

A port scan of the linux box reveals that no ports are open. Do I perhaps need to disable the firewall on my linux box to allow Outlook Express to connect to it??
 
@koffeejunkie:

No luck I'm afraid. I tried setting up my test system with just one domain. I have two gmail accounts and since gmail provides pop3 access I thought it would be the perfect dry run to test out my postfix config.

I did exactly as your posts. I'm stumped.

I created the mydomains file like so:

Code:
localhost                             OK
linux.local.lan                       OK   
gmail.com                            OK


I setup virtual as:

Code:
[email protected]            cyberstorm1
[email protected]            cyberstorm2

I then ran the following commands:

Code:
postmap hash:/etc/postfix/mydomains
postmap hash:/etc/postfix/virtual

The ran successfully with no reported error messages.

Then in/etc/postfix/main.cf I set the following:

Code:
mydestination = gmail.com, localhost

I also added these after mydestination:

Code:
virtual_mailbox_domains = hash:/etc/postfix/mydomains
virtual_mailbox_maps = hash:/etc/postfix/virtual

I also set this:
Code:
relayhost = smtp.gmail.com

I then restarted postfix. That went fine.

I then setup Outlook Express in Windows XP on the same LAN (I can ping the linux box and the linux box can ping the XP PC). My POP and SMTP server is the IP of the linux box, I specified the username and password of the user account I created (in this case: cyberstorm1)

After clicking Send/Receive, Outlook Express tried to connect to the linux box but it just times out!!

A port scan of the linux box reveals that no ports are open. Do I perhaps need to disable the firewall on my linux box to allow Outlook Express to connect to it??

NOTE: I have not yet setup fetchmail, but I have specified the

Or is there something else wrong??
 
A port scan of the linux box reveals that no ports are open. Do I perhaps need to disable the firewall on my linux box to allow Outlook Express to connect to it??

OK, this can mean one of two things:

1. Either your distro sets inet_interfaces = 127.0.0.1 in main.cf. Change this to inet_interfaces = all and restart postfix.

2. You have a firewall running. To check if this is the case, do:

iptables -L

If the output looks like this, go back to #1:

Code:
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

If it looks like anything else, do this:

Code:
iptables -A INPUT -p tcp --dport 25 -j ACCEPT

This will open port 25 on all interfaces
 
I've configured postfix exactly, I've setup fetchmail (which works great) and even opened port 25 and 110 using the method you showed me but I'm still not having any luck with this!

As a simple test, I sent an email from my work address to the POP3 address I configured in virtual and fetchmail.

I then ran fetchmail which pulled the mail message from the POP3 server.

I then configured Evolution on the same machine that I setup postfix and fetcmail on. I configured Evolution with a POP3 account, that points to localhost with the username and password of a user called cyberstorm (which was specified in the virtual file.

I then clicked Send / Receive and receive the following error message:

Error while Fetching mail

Could not connect to localhost: Connection refused



Any reason why this would be the case??

Would it be possible for you to send me samples of main.cf, virtual, mydomains and .fetchmailrc fies on working servers??
 
Last edited:
You need a pop3 server. See if your distro includes courier or if it doesn't see if it has dovecot.

Also check in which format Postfix is configured to deliver mail. Does it put it in /var/spool/mail/<username> (mbox) or in /home/<username>/some_mail_dir/ (Maildir)? You'll need to configure this to your taste. Maildir is, in my opinion a better option. It makes every mail a single file, and makes subdirectories on the filessystem for each mail folder. mbox puts all the mail on a single file, which has a filesize limit of 2GB.

In postfix you'll need this in main.cf:

Code:
home_mailbox = Maildir/

Courier and Dovecot both use Maildir by default. Courier expects to find the mail in /home/user/Maildir while Dovecot (if I remember correctly) looks for /home/user/Mail Check their configuration files.

Either ways, you'll have to make sure that:
1. The Maildir exists in each user's home directory
2. The Maildir has the same ownership as the home directory, otherwise mail won't deliver. Here's an example:

Code:
# cd /home/
# ls -lh
total 0
0 drwxrwxrwt    6 user1    users   204B Jul  1 19:24 user1
0 drwxr-xr-x   30 user2  users  1020B Aug 30 20:21 user2
# cd /home/user1
# mkdir Maildir
# chown user1:users Maildir

chown changes the ownership. the 'users' is the group, and depending on the distro you're using could be the same as the username.
 
Top
Sign up to the MyBroadband newsletter
X