Re: Some mail system problem.

Dave McFerren (davem@solve.net)
Thu, 8 Oct 1998 13:59:41 -0500 (CDT)


Chan,

There are several ways to move your mail server down to your local lan, when
your local lan is dial-on-demand. Here are some options. On all of these
options, you have to have a mail server spooling your mail for you. You can do
this by making a change in the dns tables of your dns server, and having mail
relayed for your domain.

Here is an example of what your dns tables might look like...

spooler IN A 199.199.199.10
newdomain.com. IN A 199.199.198.2
IN MX 10 newdomain.com.
IN MX 20 spooler.newdomain.com

Now on the machine that you want mail to spool on (spooler), make the sendmail
understand that he can relay mail for the newdomain.com domain.

You can do this if you are using the sendmail.8.9.1 version by creating a file
in the /etc/mail directories called relay-domains and putting newdoamin.com in
it.

This will make any email first try to be delivered to the newdomain.com address
first, and if the newdomain.com machine is not available, email will be
delivered to the spooler.newdomain.com address. The spooler machine will accept
you mail and put it into the spool of its own email. This mail will try to be
delivered to the newdomain.com machine every 15 minutes, if you started the
sendmail deamon on the spooler machine with the -q15m option.

Now that you have the mail spooled on another machine upstream of your internet
connection, how do you get the mail down to your machine on a timely basis?
This is where the options come in.

Option 1.

You can synch the times on each of the machines such that you know the time the
sendmail deamon is going to try to send out mail on your spooler machine, and
connect a couple of minutes ahead of time. You can do this by running a cron on
the spooler machine like this.

3 * * * * /usr/sbin/sendmail -q

This will try to send mail out 5 minutes after every hour. Just make sure you
are connected at the top of the hour anytime you want your mail to be delivered.

I run a cron on the newdomain.com machine that connects and sets the time every
hour. This will make the dail-on-demand link come up every hour if it is down,
synch my time, and get my mail. Here is what this cron looks like...

0 * * * * /usr/sbin/netdate 199.199.199.200; /sbin/clock -w

The clock command writes the proper time to the bios of the machine, so that if
it reboots, there is still time synch.

You may want to change the time for connection at night, if noone is going to
use the mail.

Option 2.

You could run a cron on the newdomain.com machine to connect to a certain port
to running deamon on the spooler machine. Connection to that port and deamon
will initiate the sendmail to send the mail. This is nicer, since you can go
get your mail at any time, and not be limited by a cron. You could even put his
in the ip-up file for pppd or diald to run after connection, so that anytime
your machine makes the connection, it forces the spooler machine to push down
the mail.

Here is a little perl script that starts a deamon on the spooler machine...

----------------------- snip snip ----------------------
#!/usr/local/bin/perl -w

require 5.002;
use strict;
BEGIN { $ENV{PATH} = 'usr/ucb:/bin' }
use Socket;
use Carp;
use FileHandle;

sub spawn;
sub logmsg { print "$0 $$: @_ at ", scalar localtime,"\n" }

my $port = shift || 3567;
my $proto = getprotobyname('tcp');
socket(Server, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) or die "setsockopt:
$!";
bind (Server,sockaddr_in($port, INADDR_ANY)) or die "bind: $!";
listen(Server,SOMAXCONN) or die "listen: $!";

logmsg "server started on port $port";

my $waitedpid = 0;
my $paddr;

sub REAPER
{
$waitedpid = wait;
$SIG{CHLD} = \&REAPER;
}

$SIG{CHLD} = \&REAPER;

for ( ; $paddr = accept(Client,Server); close Client)
{
my($port,$iaddr) = sockaddr_in($paddr);
my $name = gethostbyaddr($iaddr,AF_INET);

logmsg "connection from $name [",inet_ntoa($iaddr), "] at port $port";

spawn sub
{
exec '/usr/lib/sendmail -q' or confess "cant exec cat: $!";
print "There is now mail for you";
sleep 30;
}
}

sub spawn
{
my $coderef = shift;

unless (@_ == 0 && $coderef && ref($coderef) eq 'CODE')
{
confess "usage spawn CODEREF";
}
my $pid;
if (!defined($pid = fork)) {
logmsg "cannot fork:$!";
return;
} elsif ($pid) {
return;
}
open(STDIN, "<&Client") or die "Cant dup client to stdin";
open(STDOUT, ">&Client") or die "Cant dup client to stdout";
STDOUT->autoflush();
exit &$coderef();
}

----------------------snip snip -----------------------

And here is a little script that will connect to that port from the client
machine.

---------------------snip snip --------------------------
#!/usr/local/bin/perl
require 5.004;
use strict;
use Socket;
my ($remote, $port, $iaddr, $paddr, $proto, $line);

$remote = shift || 'localhost';
$port = shift || 3567;
if ($port =~ /\D/)
{
$port = getservbyname($port,'tcp');
}
die "no port" unless $port;
$iaddr = inet_aton($remote) or die "no host: $remote";
$paddr = sockaddr_in($port, $iaddr);

$proto = getprotobyname('tcp');
socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
connect(SOCK, $paddr) or die "connect: $!";
while ($line = <SOCK>)
{
print $line;
}

close (SOCK) or die "close: $!";
exit;

----------------------------------snip snip -------------------

I got the majority of the code off the internet, so if you don't like to run
things in perl, or you would like to do this other ways, you have lots of
different methods. Anyway, this is how I solved the problem.

-----------------------------
Dave McFerren davem@solve.net
System Administrator
Net Solutions, Inc.
816-220-0303 fax 816-220-0333
-----------------------------
"It never hurts to help!"

> From owner-linux-net-outgoing@vger.rutgers.edu Thu Oct 8 09:44 CDT 1998
> X-Sender: sandy@202.187.117.7 (Unverified)
> Date: Thu, 08 Oct 1998 20:57:30 +0800
> To: linux-net@vger.rutgers.edu
> From: Chan Foo Bang <fbchan@extol.com.my>
> Subject: Some mail system problem.
> X-Orcpt: rfc822;linux-net@vger.rutgers.edu
> X-Loop: majordomo@vger.rutgers.edu
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> I need your expertise and suggestion on this matter...
>
> Currently, our system is using a 64K ISDN dial-up. As you all know, ISDN
> dail-up is not UP all the time and it only active when there is people
> surfing or activiti in the internal network. We also have a fix ip address.
> We are using linux firewall and have a mail server in our local network
> (behind the firewall). Our parent company have a 64K lease line. So since
> we can't host our internet mail server in our organisation( we are using
> ISDN dial-up), so we make use of our parent company lease line to host our
> mail server. We register our domain name and whatever mail for this domain,
> it will send to the mail server that we set up and located in our parent
> company. So when a user want to read a mail, they need to connect to the
> mail server in the parent company to retrieve mail. Sometime it is very
> uncovenience and sometime the downloading mail from this mail server to the
> user workstation is very very slow. So what you guy will suggest to solve
> this problem?
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.rutgers.edu