<!doctype linuxdoc system>
<!--

       HOWTO:   "Linux off-line mailing method" by Gunther Voet
                 Offline-Mailing

 DESCRIPTION:   "how to use your linux offline - and still use different
                 email addresses"

    REVISION:   v1.3.2
INITIAL DATE:   21 April 1997 - 21:47. (CET)
 LAST UPDATE:   10 Juny 1997 - 15:01. (CET) (see change)
SGML CONVERT:   15 September 1997 - 16:46. (CET)
      CHANGE:   04 June 1998 - 2:33. (CET)
-->


<article>
<title>Linux off-line mailing method (offline mailaddr with 1 account)
<author>Gunther Voet, <htmlurl url="mailto:freaker@tuc.ml.org"
name="freaker@tuc.ml.org"> - Belgium (CompuMed/TuCSRV)

<date>v1.3.3, 4 June 1998

<abstract>
Use your linux mailing system offline, receive mail for multiple users
with only one email address, and without being 24-24 online on the net.

If you are unable to pay a direct line to stay online for 24-24 and still
want your users to receive mail on your linux box; as well not pay for a
multi-drop box at your isp, you can use this system using only one email
address to divide to your users email addresses. It is as well 24-24
reachable since the server where your account resists will receive the
mail.

<ref id="copyright" name="This howto is Copyright (c)1997-98 by Gunther Voet.">

</abstract>

<toc>

<sect>Notes by the author (preface).
<p>
In this chapter i'm just going to put myself safe for any damages and
flames - since even *I* could be wrong ... If you got any questions or
suggestions to add to this faq, even if you find any faults - there is a
feedback section in it ...
<p>
Some "need to know" point is, all filenames & files/types are indicated
with the line:
<p>
<quote><tt>(*** &lt file &gt *** text ***)     .procmailrc</tt></quote>
<p>
This means, this is a file, called ".procmailrc" containing text. The text
variable can also be code. It shows you what name of file to use. Without
a path means it can be variable/choosen by you (in the most cases this
files resists in the homedirectory of the mail"user" like /home/mailer).

<sect1>Legal stuff
<p>
Neither the author nor the distributors of this HOWTO are in any way
responsible for physical, financial, moral damage incurred by following
the suggestions and examples of this text. The information in this document
contains the best of my knowledge and experience, but i could still make
any mistakes as well in the information as in the examples. Any trademarks
are property of their respective holders (i ain't using any commercial
thingy's here - but well - IF i'm going to add some text, i don't need to
change this disclaimer). If your cat dies 'coz this document was too
heavy - i am not responsible as well ...

<sect1>Copyrights<label id="copyright">
<p>
This document and contents are Copyright (c)1997-98 by Gunther Voet.
Unauthorized (re)production in any form is explicitly allowed and even
strongly encouraged as long you don't change the contents of it without
contacting the author (Gunther Voet). If you quote the document as whole
or a part of it, there needs to be a Copyright "hint" or link to the
derived work. "The HOWTO documents are copyrighted by their respective
authors". The "HOWTO copyright" will discuss what can be done and what
cannot be done with this document. If it is used in a commercial way,
the author should been noticed for such distributions. Exceptions on this
copyright may be granted under certain conditions with a written letter or
e-mail to the author. For more info about the standard HOWTO disclaimer,
please contact linux-howto@sunsite.unc.edu.

*PLEASE* *IF* you are going to make a system based on this HOWTO, then
PLEASE give me the copyright :) heh ... - i am not that cruel :)). I mean
by a system "a package" - NOT the mailsystem itself - altough it is some
appreciative thingy i would be included :)) i can always use one email
address more for more flaming :)) (just kiddin').


<sect1>Feedback
<p>
Well, i expect from you and the users who read this HOWTO, they will
make this HOWTO useful. If you got any suggestions, corrections, comments
(except flame-mail :)) - please send them to me at freaker@freestamp.com or
<htmlurl url="freaker@tuc.ml.org" name="freaker@tuc.ml.org">
and i will make the corrections, comments or 
suggestions happen in the next revision. If you publish this document on
a commercial way, a complimentary copy would be appreciated - you can mail
me for my postal address. For flames - you could send them to me, but they
will end at /dev/null ... so - don't even mind to waste bandwidth for it !.
Since i can exclude some users to receive mail from (explained in this 
document) (evil grin). My alias (name) is freaker btw :)). You can always
try "freaker@freestamp.com". (note the changed address !!)

<sect1>Distribution
<p>
The latest revision of this document can been get from:

<htmlurl
url="http://sunsite.unc.edu/pub/Linux/docs/HOWTO/mini/Offline-Mailing"
name="http://sunsite.unc.edu/pub/Linux/docs/HOWTO/mini/Offline-Mailing">

-and-

<htmlurl url="http://tuc.ml.org/om/" name=
"http://tuc.ml.org/om/">

(also checkout <htmlurl url="http://tuc.ml.org/"
name="http://tuc.ml.org">)

tuc.ml.org could be down at the time of current writing!

<sect1>Changes
<p>
<verb>
 v1.0.0       - Preliminary release, internal testing, we tried it before
                we gave it out to you :) .. since - it GOT to be usefull
                and needs to work? rite ? :)
 v1.1.0       - Fixed a lot of errors in the texts, put chapters in it,
              - fixed some small errors and typo's ...
 v1.2.0       - fixed grammatical errors.
              - added a "what-are-we-using" chapter.
              - added Sunsite address.
 v1.3.0       - Added "virtual mail support" for admins
              - New site and email addresses
              - Thanks go to ...
 v1.3.1       - Converted to SGML and fixed some minor details.
 v1.3.2       - Major errors corrected (filenames .fetchmailrc to
                .procmailrc) etc... (thx to Tetsu Isaji)
              - Added support for the "new" sendmail, v8.8.0+
              - Fixed some minor errors
              - Upgraded my system YAY!
              - Japanese version will come out soon, location
                will be mentioned when known ... (thx to Tetsu Isaji)
 v1.3.3       - Added CC support, changed email addr to freaker@freestamp.com
</verb>

<sect1>What am i using ?
<p>
I'm using Linux 2.0.30, Pentium-166, ATI pci-mach64 card, Accelerated-X
(Metro) and a connection to my isp (currently ibmnet) via ppp using a ZyXEL
28k8 modem, and occasionally a Bausch 28k8. 

Now i upgraded to Linux 2.0.33, installed a USRobotics modem, it still
works as it should work :) (everybody should upgrade their linux versions
as soon there comes out a patch :) believe me :) you could spare a lot of
time & seeking for errors when doing this one :)

<sect1>Thanks go out to ...
<p>
<itemize>
<item>Fred, durban.hebel.net (for allowing the pages & bot)
<item>Lifesaver, parkside.net (for allowing the new pages, helping with this
   faq for mailing, since, it is all working overthere and here ... make
   some visit to his cyber-cafe ... heard they got great coffee :))
<item>The server admins at lodus.net to continue this project.
<item>Now i'll need a new server since lodus.net has been sold :(
</itemize>

<sect>Preliminaries
<p>
Well, how does this system works ? what can you do with it ? what is it
anyway ? and ... am i used to read it ? ... to all those questions - there
is an answer ...


<sect1>Preface & Description
<p>
This HOWTO is dedicated to all the off-line linux users/servers ...
You got a group, or organization, and you want all your members to have
a contact (email) address, without paying for the 24/24 direct line or for
the email accounts ... Or you got a internal network - with a masq'd server
and you want to give all the users using it a email address, you could use
this way to do it. I personally am using it to give my users & members of
a demogroup all a e-mail account without being 24/24 online; since it is a
non-commercial demogroup - and we don't got THAT much money to pay a direct
line with instant email access - and different ip's. Everybody got a email
address, even when they don't got internet access. The ones with internet
access can receive their mail on their personal email address - viavia the
system described below. Your users can still send mail as they used to do,
since - your system will hold the mail queue from the users. The only thing
what should be changed for the users - is that they add their "email address"
wether (described below) it is the method with the subject line, or with the
header "to" ...


<sect1>Points of interest ...
<p>
<itemize>
<item>A organization with members, for all a email address, so they can be
   contacted when neccesary.

<item>A anonymous mailservice - they can't read your "mail setup file" - so they
   don't know where the mail is forwarded/rerouted to.

<item>A group who doesn't got enuf money (don't laugh), or is free, and don't
   WANT to spend money for it (eheh) - and still wants to provide the members
   a email address.

<item>A masq'd network - with a server connected to the internet, where the users
   using the masq'd network need to have a email account

<item>You want to put some documents "autoreplied" - like i do with my
   HOWTO, statistics, or documents ... like "info@yourmail.dom" or
   "document1@yourmail.dom".
 
<item>You only need one account at the "main" server to fetch from, for the
   +200 email accounts you can create at your server ...

<item>I used the "B" method with +- 300 email accounts - with a public
   server; 80486DX4-100 - and was processed in 1 minute.
</itemize>

<sect1>Things you should know
<p>
<itemize>
<item>Not every (free) mailservice is happy when you are going to distribute
   mail to other users, or putting up an anonymous mail server, so, please
   try to contact your mailserver administrator before "just doing it".

<item>It is slower than a direct 24/24 connection, since your server will need
   to get online before it will process the mail.

<item>It needs a administrative force to administrate the "mailrouting" and to 
   add the user ... you will need work with it ! - it is not that automatic.
   (well - i made it "semi-automatic" with my server :) you could try it as
   well).

<item>Bandwidth and space is needed when you got many users - on the mailserver
   you are working on ... and sure - when they send files - you need to have
   enough space on it !.

<item>All mail will be transferred into "one step" - so - the last mail received
   on your server will be last sent to the recipient. "first in - first out".

<item>In the first method (to:) there is no prob with the usernames - but in the
   second "cheaper" method - users can't put in a subject line, since that
   one will be used to send the mail to the recipient. Many users forget to
   use the "subject" ... - or they will need to know it clearly.

<item>If you poll enough for your mail, (for example 4 times a day) - the mail
   will be sure be delivered to as from a recipient the least every 6hrs. So
   the processing will go a little smoother.

<item>you CAN use it as a "online" mail server as well :) since it will poll
   for it's mail for every XX minutes. but - when you are online - why using
   another server ? and not asking your own domain for your own server ?
   (dough).
</itemize>

<sect1>there are 2 different ways ...
<p>
<enum>
<item> method 'A' - now called "(m(A))".
  
   The "mailsystem" will look to the header, and will see to the "to:" line.
   This is the best way, since it are "real email addresses". You will need
   another account on some server *AND* you need a DNS (MX) entry (your own
   domain for instance). If the system administrator wants to help you with
   that, then there will be no problem !. The system administrator will need
   to reroute ALL mail sent to your (MX) maildomain -> to your account !.
   This will take some time for him to do it :) so be really nice to him :))
   Thanks to my system administrator (Fred) i got my maildomain and the user-
   services of my "free" demogroup. It can be a DNS entry costs something,
   what you will need to consider to take it or not.

<item>method 'B' - now called "(m(B))".

   The "mailsystem" looks to the subject line, and will forward to the user
   indicated into the subject line. If the user is not found, it will bounce
   a mail back. This will need a pop server with only one useraccount, and
   don't need your own DNS or you don't need to be nice to your system-
   administrator who arranges you the mail address :). You can use a public
   mailserver, as well your own mailserver or a private one. You can even
   sacrifice your own email address for it :). I used this approach as first
   what worked for me for over a year now ... I know this is sloppy, but, i
   ain't telling you need to use this way, so don't shoot ME - since i'm only
   offering you some solutions to your mail problems :) - you could use
   method A what isn't that sloppy !
</enum>

<sect>Requirements
<p>
Well, you need (of'course) a Linux machine, what can be connected to the
internet - So! (i am smart - i am smart :)) - you probably got a modem, right?
a phoneline - or any way to connect yourself with the server you are running.
You will also need some software like Fetchmail, Procmail, an extra account,
and your email account or DNS with email account.


<sect1>A linux machine
<p>
This can be ANYthing ... even a 8086 ... - but preferable - since there will
be some load on it - minimally a 80386 :). as faster the machine - as faster
the software will run (rite eh)? :).

<sect1>A extra account at your linux machine
<p>
You need to create a extra account on your Linux machine. I am using as
example (in this HOWTO) "mailservice". This can be as well "mailserver"
or "mailtousers" - as long it is some name what can be recognized by you!.

           ! It doesn't need to have ANY root privileges ! 

This mailaccount will forward all mail to the users on your system, or to
external users (not on your system :)). Just create it as an ordinary user. 
You will need to test things under this account, and, the mail 
"administrator" can use this account to administrate the mail account without
being root even .. so - pretty safe !.

<sect1>Fetchmail 
<p>
I am using v1.9 patch level 9 ... i found it at sunsite.unc.edu, and, i
am using only this mail-fetcher in my example - if you want to use another
one, you are on your own ! since i am happy with it :). For extended features
you should read the man of Fetchmail :). This can be installed as root - as
well for the user itself ... - best is to install it as root :) since i know
it will work for sure then :)))

<sect1>Procmail
<p>
I am using v3.10 - found it again at sunsite.unc.edu, and - i like this as
the best mda (mail delivery agent) around ... It delivers nicely - and it
is better than using it by the "original" system mda - since it will deliver
user-per-user ! ... The same as above - it can be installed as root, or as
user - and :) best is to install it as root - since i know it will work for
sure then (again!) :)... how repetetive ...

<sect1>A mail account
<p>
You always need to have a mail account - where you can "poll" your mail from.
The server needs to be a POP server - where you can poll from when you want,
and where users can send their mail 24/24 to. It can be a free-mail service,
as well commercial - even your mailaccount is sufficient enough. In the 
"subject" method (m(B)) - you don't need something more - in method A - with
the "to" fields - you NEED more - as written below !

<sect2>A DNS record (MX)
<p>
Needed to run your own "domain" - email domain ... it is needed since the
administrator of the server can't use it's own domain for your users - since
there are users who need to be contacted on his server as well - what could
interfere with your users. And your mailheader must be filtered on that
domain. So - an apart domain - pointing to HIS server. This can be an
additional cost - or you can ask your system administrator to add a "non-
authorative address" - pointing to his server ... - however - it needs to be
another domain than he is using !

<sect2>A "forward" to your account-account :)
<p>
Well, the system administrator needs to forward *ALL* mail to your domain
to YOUR account ... - it is easy for him when he knows how to do it :) .. 
else he will need to read the sendmail manual :)) (or qmail - whatever).
You will poll for your mail at your account and voila ! filtering on YOUR
own email domain.

<sect>I got it all, what now ?
<p>
Now you created the extra account, you got the mail address - and/or the DNS
entry & forwarding to your account ... As well installed Procmail & Fetchmail
so we can rock the place ! :) .. here we go !
<enum>
<item>You need to create a .procmailrc file, what will contain the "delivery"
   info to your users.
<item>You need to create a "nosuchuserfile" - so the writer knows his mail isn't
   delivered well.
<item>For best work :) you could use crontab to check for mail. This is a easy
   way to check your mail every XX minutes when on the internet.
</enum>

<sect1>Creating a .fetchmailrc file
<p>
You will need to create a .fetchmailrc file, what will contain the information
(username & password, as well the Mail Delivery Agent (mda) to proces the mail
to). Here is some example file ...
<p>
<quote><tt>(*** &lt file &gt *** text ***)     .fetchmailrc</tt></quote>
<tscreen><code>
server my.mail.server.com
proto pop3
user myaccountthere
pass deepestsecrets
flush
mda /usr/bin/procmail
</code></tscreen>
<p>
This file will be used to fetch your mail. Please test it by using the
fetchmail program "fetchmail -vv" - and see your mail is being transferred
right ... There will be some errors - since the procmail control file hasn't
been created yet. You can wait by testing AFTER making the procmailrc file,
but - i'll warn ya - IF there is something fault :) it CAN be this file :)
It needs to be owned by the user account itself - in my case "mailservice"
and needs to be "user readable" but NOT group/world readable - since it
contains the "main password" :)). (chmod 600 .fetchmailrc will do).

<sect1>Creating a .procmailrc file
<p>
This control file will forward all mail to the users in it. There are 2 ways
as described before - the "to:" (header) way - and the "subject" (sloppy) way.
The file will contain the usernames to transport to. All the "#" are comments
and are absolutely not needed when not wanted - it's only so you know what i
am doing ... - you can as well best chmod it 600 - so the rest of the world
or group doesn't need those private addresses eh :) ... It needs also to be
owned by the user (like "mailservice") :)). The "nosuchuserfile" is a
"bounce" to the writer - if the user isn't found (so mail not delivered) in
the procmailrc file ... - so the writer knows the mail isn't delivered well.

<sect2>For "header (to:)" transportation
<p>
<quote><tt>(*** &lt file &gt *** text ***)     .procmailrc</tt></quote>
<tscreen><code>
# this line is for debugging purposes only ! it should be removed for
# ethical purposes - since you can read all mail passed trough your mail-
# server ... - all mail will be copied to the file "passtrough" before
# going to the users ... herein you can look what went wrong ...
:0 c
        passtrough

# the mail with header "to: freaker@mydom.com" will be forwarded directly
# to me, the other mail will pass this option ... 
:0 
* ^To:.*freaker@mydom.com
! freaker

# the mail to root@mydom.com will be forwarded to root ... as well postmaster!
:0 
* ^To:.*root@mydom.com
! root

:0 
* ^To:.*postmaster@mydom.com
! postmaster


# the mail to barbara@mydom.com will be forwarded to barbara AND will be
# forwarded to her private email address !

:0 c
* ^To:.*barbara@mydom.com
! barbara@her.private.one

:0 
* ^To:.*barbara@mydom.com
! barbara

# the mail to johnny@mydom.com and johnny@hisdom.com will be forwarded to johnny

:0
* (^To:.*johnny@mydom.com)|(^To:.*johnny@hisdom.com)
! freaker

# the mail to hans@mydom.com and all carbon copys will be forwarded to hans

:0
* (^To:.*hans@mydom.com)|(^CC:.*hans@mydom.com)
! hans

# this lines will BOUNCE the mail to the sender - when it is not delivered to
# one of above users ... it will send the file "nosuchuser" into the mail
# body as reply ... be aware ! you need to make such file ! - mine contains
# "well, the user you wanted to reach does not exist on this server, please
# try again, it could be the user is not present anymore".
#
:0
  |(/usr/bin/formail -r -k \
     -A"X-loop: mailservice@mydomain.dom "| \
       /usr/bin/gawk '{print }\
       /^/ && !HEADER \
         { system("/bin/cat nosuchuser"); \
         print"--" ;\
         HEADER=1 }' ) |\
         /usr/bin/sendmail -t


exit
</code></tscreen>
<p>     
        
<sect2>For "subject: touser" transportation
<p>
<quote><tt>(*** &lt file &gt *** text ***)     .procmailrc</tt></quote>
<tscreen><code>
# this line is for debugging purposes only ! it should be removed for
# ethical purposes - since you can read all mail passed trough your mail-
# server ... - all mail will be copied to the file "passtrough" before
# going to the users ... herein you can look what went wrong ...
:0 c
        passtrough

# the mail with header "to: freaker@ibm.net" will be forwarded directly
# to me, the other mail will pass this option ... When you got a "dedicated"
# email address to receive your "mailservice thingy's" on - you don't need
# to use this line :) 
:0 
* ^To:.*freaker@ibm.net
! freaker

# all mail with as subject "root" will be forwarded to root !
:0
* ^Subject:.root
! root

# all mail to "subject: barbara" will be forwarded to barbara ...
:0
* ^Subject:.barbara
! barbara

# all mail to "subject: paul" will be forwarded to his external email addr.
:0
* ^Subject:.paul
! paul@his.personal.emailaddress

# all mail to "subject: john" will be forwarded to his account at your server
# and a copy will go to his private email address ... 
:0 c
* ^Subject:.john
! john@his.personal.emailaddress

:0 
* ^Subject:.john
! john

# All the mail from ibm, with their updates and information, will go to                                
# freaker, as he is the one who will administrate the mailservice, and
# as ibm doesn't want to get the bounce putten below !! ... this is
# neccesary if your mail provider sends "newsletters" etc...
:0
* ^From:.*newsletter@ibm.net
! freaker

# All messages from the daemon should been thrown away, or in my case, will
# be saved to a file ... (use /dev/null to throw to endless pits of The Abyss)
:0
* ^FROM_DAEMON
throwaway

# this lines will BOUNCE the mail to the sender - when it is not delivered to
# one of above users ... it will send the file "nosuchuser" into the mail
# body as reply ... be aware ! you need to make such file ! - mine contains
# some text like "user not found in subject line, please use "Subject: user"
# to write a mail to the user, like example "subject: freaker" would send a
# mail to freaker." The file can be long, but also small :) ... the
# "mailservice@mydomain.dom" will prevent to loop between your server and
# the other server - it needs to have the EXACT email address used !.
# Else you could create an endless loop with a server what sends mail
# to "your email address" with as subject something like "don't spend 500$
# at your ..." etc...
:0
  |(/usr/bin/formail -r -k \
     -A"X-loop: mailservice@mydomain.dom "| \
       /usr/bin/gawk '{print }\
       /^/ && !HEADER \
         { system("/bin/cat nosuchuser"); \
         print"--" ;\
         HEADER=1 }' ) |\
         /usr/bin/sendmail -t

exit
</code></tscreen>
<p>

<sect1>"nosuchuserfile"
<p>
<quote><tt>(*** &lt file &gt *** text ***)     nosuchuser</tt></quote>
<tscreen><code>

The user you wanted to contact is not present at this system.

Please use the subject line as recipient - example "subject: freaker" would
send mail to freaker on this system.

</code></tscreen>
<p>

<sect1>"crontab files".
<p>
If you don't know how crontab works :) better read the manual :) ...
You need to create a "checkmail" file - what will see if the link is up,
as well the cronfile itself ... - i am using a ppp link :) so - this is an
example how to look when the ppp link is up - and to poll every 10 minutes
using cron. Looks sloppy - but isn't !.


<sect2>checkformail
<p>
the .checkformail file will be called (needs to be executable as well) - and
will look if the ppp link is up. If it is up - then it will fetch for mail.
Crontab will use this file when you are using the below cronentry ...
<p>
<quote><tt>(*** &lt file &gt *** code ***)     .checkformail</tt></quote>
<tscreen><code>
#!/bin/sh
#

        cd /home/mailservice

        if [ -f /var/run/ppp0.pid ]; then
        /usr/local/bin/fetchmail -s > /dev/null 2>&1
fi
</code></tscreen>
<p>
<sect2>crontab
<p>
This cronentry file needs to been loaded into crontab, and will call the .checkformail - every 10 minutes. It won't write any mail or give any info
to the console - since i'm redirecting everything to null.
<p>
<quote><tt>(*** &lt file &gt *** text ***)     cronentry</tt></quote>
<tscreen><code>
0,10,20,30,40,50 * * * *  /home/mailservice/.checkformail 1> /dev/null 2> /dev/null
</code></tscreen>
<p>

<sect1>"At the admins site".
<p>
Well, this should be done when using the "A method" ... at the admin's site,
so the email goes all from a complete domain, to one username. It is pretty
simple, and once you've done it - it works like hell. this is NOT neccesary
if your system administrator (the uplink) got another method, and is NOT
neccesary at YOUR side !!!!
<p>
When using a newer version of sendmail, the "old sendmail" trick probably
won't work, so please refer to the "new sendmail" topics to let your
mailrouting work.
<p>
<sect2>(old sendmail) add some lines to sendmail.cf
<p>
add the following lines to your /etc/sendmail.cf file, so the domains file
will be read.  please be noted that the "ruleset 98" is added as underhere,
since - once you got errors :) it's a hell to find 'm out ! (and i can know
it :) DuH).
<p>
<quote><tt>(*** &lt file &gt *** add ***)    /etc/sendmail.cf</tt></quote>
<tscreen><code>
# Database of handled domains

Kmaildomains btree /etc/maildomains.db

# Add these lines *IN* Ruleset 98 ! (under Ruleset 98).

R$+ < @ $+  . >		$: $1 < @ $2 > .
R$+ < @ $+ > $*		$: $(maildomains $1@$2 $: $1 < @ $2 > $3 $)
R$+ < @ $+ > $*		$: $(maildomains $2 $: $1 < # $2 > $3 $)
R$+ < @ $* > .		$: $1 < @ $2 . >
</code></tscreen>
<p>

<sect2>(new sendmail) Adding some lines to sendmail.cf
<p>
With the newer sendmail releases (tested with sendmail v8.8.7, 8.8.8).
Ignore method A, and add the next lines ...
<p>
<quote><tt>(*** &lt file &gt *** add ***)    /etc/sendmail.cf</tt></quote>
<tscreen><code>
# Database of handled domains

Fw/etc/sendmail.cw
Kvirtuser btree /etc/maildomains.db

*OR*

Fw/yourhomedir/sendmail.cw
Kvirtuser btree /yourhomedir/maildomains.db

</code></tscreen>
<p>

<sect2>(new sendmail)editing the /etc/sendmail.cw (or /yourdir/sendmail.cw) file
<p>
If you are using another "location" for the sendmail.cw file, then please
replace the "/etc/sendmail.cw" to "/yourhomedirectory/sendmail.cw". The
pro points of putting this sendmail.cw file into your homedirectory is
that you don't need root to change the domains to receive on. tough - this
can give security risks if not used properly !

This file can already exist, or needs to be created, if it already exists
be sure you don't overwrite the older data - or i need to refer you to my
fine disclaimer :)

First create a /etc/sendmail.cw file, what will be used to "send" a domain
to a specific user ... here is an example ... (as you already knew, the name
"mailservice" can be anything you want - it can even be your loginname (like
mine is freaker).
<p>
<quote><tt>(*** &lt file &gt *** text ***) /etc/sendmail.cw</tt></quote>
<tscreen><code>
mydomain.dom		mailservice
</code></tscreen>
<p>

<sect2>creating a /etc/maildomains file
<p>
First create a /etc/maildomains file, what will be used to "send" a domain
to a specific user ... here is an example ... (as you already knew, the name
"mailservice" can be anything you want - it can even be your loginname (like
mine is freaker). (you could have this /etc/maildomains in
/yourhomedir/maildomains as mentioned before, just change the paths :)
<p>
With the OLDER sendmail versions:
<p>
<quote><tt>(*** &lt file &gt *** text ***)     /etc/maildomains</tt></quote>
<tscreen><code>
mydomain.dom		mailservice
</code></tscreen>
<p>
With the NEWER sendmail versions:
<p>
<quote><tt>(*** &lt file &gt *** text ***)     /etc/maildomains</tt></quote>
<tscreen><code>
@mydomain.dom		mailservice
</code></tscreen>
<p>

<sect2>let it work !
<p>
With the old & new sendmail versionsyou need to generate the btree
(database) files, you'll need to do the following:
<p>
<verb>
cd /etc    (or /yourhomedir)
makemap btree maildomains < maildomains
</verb>
<p>
after that, kill the sendmail daemon, and restart it. it should now WORK!
good luck :)

<sect>Automation
<p>
Well, now, everything above works ... (if it doesn't work - don't even think
about automation before it WILL work ... - now - we need some script so it
isn't a pain in the ass for the "mailadministrator" or the root user to add
users to the procmailrc file ... The below example will be for "more 
experienced users" - since some things NEED to be changed as well ... - it
is an example with the "B method - Subject lines". It can be easily adapted
to the "A method". Since the "B method" will be more used (cheaper) than the
"A" method - i decided to use the "B method" ... Am i sounding repetitive or
not ? .. well - i meant to write it in this way :)) to bug you :)))..

<sect1>The "skeleton".
<p>
Since the footer needs to be as footer (everything below won't be processed
since we are bouncing there); there needs to be a header and a footer file.


<sect2>the ".procmailrc-header" file
<p>
This file will now be the "header & user" file .. since here will users been
added and removed - it will be a important file ... - best take a backup from
it each time you add a user ... - there COULD be something wrong sometime ..
A system can fail ...
<p>
<quote><tt>(*** &lt file &gt *** text ***) .procmailrc-header</tt></quote>
<tscreen><code>
:0 c
        passtrough

:0 
* ^To:.*freaker@ibm.net
! freaker

:0
* ^Subject:.root
! root

:0
* ^Subject:.barbara
! barbara

:0
* ^Subject:.paul
! paul@his.personal.emailaddress

:0 c
* ^Subject:.john
! john@his.personal.emailaddress

:0 
* ^Subject:.john
! john

:0
* ^From:.*newsletter@ibm.net
! freaker

:0
* ^FROM_DAEMON
throwaway

</code></tscreen>
<p>

<sect2>the .procmailrc-footer file ..
<p>
As mentioned above, this file needs to be as footer - since all data BELOW
it won't be used to deliver - this footer contains the "bounce" code to 
bounce the users not found *ABOVE* this footer !. it is the ABSOLUTE end of
the file !
<p>
<quote><tt>(*** &lt file &gt *** text ***) .procmailrc-footer</tt></quote>
<tscreen><code>

:0
  |(/usr/bin/formail -r -k \
     -A"X-loop: mailservice@mydomain.dom "| \
       /usr/bin/gawk '{print }\
       /^/ && !HEADER \
         { system("/bin/cat nosuchuser"); \
         print"--" ;\
         HEADER=1 }' ) |\
         /usr/bin/sendmail -t


exit

</code></tscreen>
<p>

<sect1>addmail script
<p>
This script will add a user to the header file, attach the header & footer
to eachother - so it will be a complete .procmailrc file. the "#" (comments)
are not really needed - and are for your info :).
<p>
<quote><tt>(*** &lt file &gt *** code ***)     addmail   (* chmod 500 *)</tt></quote>
<tscreen><code>
#/bin/sh
#
# Copyright (c)1997 by Gunther Voet. rev 1.0.1
# please leave the Copyright in it when it is distributed with any
# system using this thingy ...

echo ""
echo "Addmail v1.0.1 by Gunther Voet, Freaker / TuC'97-98 (21/04/97)"
echo ""

if [ $1 ]; then

        if [ $2 ]; then

# make a backup file !        
        
        cp /home/mailserv/.procmailrc-header /home/mailserv/.procmailrc-backup
        
# APPEND (>>) the information to the header file ...        

        echo ":0" >> /home/mailserv/.procmailrc-header
        echo "* ^Subject:.$1" >> /home/mailserv/.procmailrc-header
        echo "! $2" >> /home/mailserv/.procmailrc-header
        echo "" >> /home/mailserv/.procmailrc-header

# copy the header file to .procmailrc - and append the footer file to it !

        cat /home/mailserv/.procmailrc-header > /home/mailserv/.procmailrc
        cat /home/mailserv/.procmailrc-footer >> /home/mailserv/.procmailrc

# make sure it is owned by "mailserv" and the read/write priveleges are ONLY
# for the user "mailserv" itself ...

        chown mailserv /home/mailserv/.procmailrc
        chgrp users /home/mailserv/.procmailrc
        chmod 600 /home/mailserv/.procmailrc
else
        echo "No DESTINATION mail address has been given ..."
fi

else
        echo "usage:"
        echo ""
        echo "syntax:  addmail from_user to_user(domain)"
        echo ""
        echo "example: addmail freaker freaker@myemail.dom"
        echo ""
fi
</code></tscreen>
<p>
Now, this script will append the information of the user, as well the email
address to the header file, it will copy it to the .procmailrc file, and will
add the footer to it, so you got a complete .procmailrc to process the mail.
If you want to delete a user- just edit the .procmailrc-header file, and
at the next user added it will be deleted at the .procmailrc. To do a instant
delete, just delete the user from both the files .procmailrc & .procmailrc-
header.
<p>
I guess you are smart enough to write a script that'll automatically add
your users when using both methods - when doing a "adduser" at your box.

<sect>Help! (sigh)
<p>
Well, you need help - isn't :) ... hmm .. i could be sarcastic and just say
"you could better do it again, 'coz it looks a messy enuf" - or .. i could
help ... - I wrote down some common problems - IF you got any problem NOT
listed in this HOWTO (section) - then mail me - and i'll put it in this howto
even with your name/email addr in it :). **BEFORE** mailing to me - please
look if you didn't forgot anything - and IF you want some help from me - send
me the MOST DETAILED information - included the scripts & things you needed.
i DON'T need any binaries - since i won't run them.
<p>
<sect1>The automation script just doesn't work:
<p>
<itemize>
<item>is it executable ?
<item>is your (default shell) located at /bin/sh ?
</itemize>
<sect1>What do you mean by "anonymous mailserver"?
<p>
<itemize>
<item>Well, you could make accounts like "anon0001@yourdom.dom" - and forward
     it to another email address ... nobody needs to read the .procmailrc
     file, so YOU ONLY know the address !.
</itemize>
<sect1>My cat died
<p>
<itemize>
<item>Well, next time don't print this HOWTO out on 200 gram papers, since it
     are 10 pages it would be 2KG for the cat - it is JUST TOO HEAVY !
</itemize>
<sect1>My dog died
<p>
<itemize>
<item>hmm - can't do anything about that one - why askin' me ? ...
     Just bury it ....
</itemize>
<sect1>Linux?
<p>
<itemize>
<item>A free-unix - posix compatible - made by Linus Torvalds ... Why are you
     reading this if you even don't know what Linux is ?
</itemize>
<sect1>Can you help me with finding a mail account?
<p>
<itemize>
<item>No! - this is a howto for YOUR side, i don't care about the side of
     your isp, nor how to get your email address. 
</itemize>
<sect1>Why is the "maybe later i'll make some addition ..." removed ?
<p>
<itemize>
<item>Read point 5.5 very carefully :) and you'll see why .. it's 'coz i
     needed to add it on general request :)
</itemize>

<sect1>How do i get a "domain" ?
<p>
<itemize>
<item>Ask your local ISP/provider - he will help you with it. It could take
     days/ even weeks when asking to the Internic - your provider can help.
</itemize>
<sect1>Why are you so f*cking lame using this?
<p>
<itemize>
<item>coz i don't want to spend money - and - 'coz i feel like being f*cking
     lame USING it - i *AM* using it - so why bother?
</itemize>
<sect1>Nosuchuserfile?
<p>
<itemize>
<item>You can put in it what you want - as long you put some "needed" info so
     the original writer knows what happened with his "never delivered" mail.
</itemize>
<sect1>Can my users write/send mail too?
<p>
<itemize>
<item>This has nothing to do with the system i explained to you, read the
     sendmail manual ... - this is to RECEIVE mail - to be "always available
     at an email address".
</itemize>
<sect1>Does every user need a shell account at my server?
<p>
<itemize>
<item>Nope .. - but - it will be really hard for users not having internet
     access :) ... You could have a masq'd network - and use a computer
     connected to it - so the users can get their mail that way, or you can
     generate a link between a bulletin board and his mail, you could even
     forward it to a fidonet gate :) ... reasons enough not to give a shell!.
</itemize>
<sect1>skeletion?
<p>
<itemize>
<item>i know it is a typo - but - i like this word better.
</itemize>
<sect1>Addmail?
<p>
<itemize>
<item>No questions - for automation - you better be sure about what you are
     going to do ... since - it COULD be a trojan ya know :))) (it isn't but
     what means you need to know what scripting is before asking questions)
     It IS easy enough to interprete - that's even why i put the comments
     with it. *IF* you are going to distribute this script - leave my
     Copyright in it please ! thanks :).
</itemize>
<sect1>Why are you so cruel?
<p>
<itemize>
<item>I am not cruel :) i am nice :) i am the nicest guy of the world, of the
     universe ! NOW SCRAM! (i just want to be complete in my HOWTO, and not
     TOO much "drifting away" from my original point in the doc - so :) that's
     all).
</itemize>
<sect1>Didn't you get a complaint of excessive language ?
<p>
<itemize>
<item>Not yet, but, could be i'm filtering everything containing 'excessive'
     and language :) i don't know :))
</itemize>
<sect1>Why is this howto different than most others?
<p>
<itemize>
<item>coz sometimes reading plain howto's CAN be boring ... i wanted to
add something next to it ...
</itemize>
<sect1>locally my domain works, but remote it seems not to receive
<p>
<itemize>
<item>Check out your "sendmail.cw" file, since the domains NEED to be
     added in it !
</itemize>
<sect1>My dog died
<p>
<itemize>
<item>the rulesets don't work, i can't receive any mail, or sendmail dies
     Refer to the new section "new sendmail" - and disregard the old
     sendmail tricks. The newer sendmail should be easier to use with
     virtual domains.
</itemize>

<sect>The End
<p>
This sounds like the end ... If you find any unwanted bugs (or features :)),
then leave some feedback ... any comments & suggestions -> mail them :).
if you are still bored after reading this, please go to:
http://tuc.ml.org/  hehehe.
<p>
My thanks go out to:

Hannes van de Vel: for supporting me (hum)
Tetsu Isaji: the japanese offline-mailing & notifying me about errors :)
Greg Hankins: for notifying me about some errors in the sgml version.
Linus torvalds: of'course ... without his help this howto wouldn't be here!

</article>
