Linux off-line mailing method (offline mailaddr with 1 account): I got it all, what now ?

Next Previous Contents

## 4. I got it all, what now ?

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 !

1. You need to create a .procmailrc file, what will contain the "delivery" info to your users.
2. You need to create a "nosuchuserfile" - so the writer knows his mail isn't delivered well.
3. 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.

## 4.1 Creating a .fetchmailrc file

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 ...

> `(*** < file > *** text ***) .fetchmailrc`

> `

>     server my.mail.server.com
>     proto pop3
>     user myaccountthere
>     pass deepestsecrets
>     flush
>     mda /usr/bin/procmail

> `

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).

## 4.2 Creating a .procmailrc file

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.

### For "header (to:)" transportation

> `(*** < file > *** text ***) .procmailrc`

> `

>     # 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

> `

### For "subject: touser" transportation

> `(*** < file > *** text ***) .procmailrc`

> `

>     # 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

> `

## 4.3 "nosuchuserfile"

> `(*** < file > *** text ***) nosuchuser`

> `

>     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.

> `

## 4.4 "crontab files".

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 !.

### checkformail

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 ...

> `(*** < file > *** code ***) .checkformail`

> `

>     #!/bin/sh
>     #

>             cd /home/mailservice

>             if [ -f /var/run/ppp0.pid ]; then
>             /usr/local/bin/fetchmail -s > /dev/null 2>&1
>     fi

> `

### crontab

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.

> `(*** < file > *** text ***) cronentry`

> `

>     0,10,20,30,40,50 * * * *  /home/mailservice/.checkformail 1> /dev/null 2> /dev/null

> `

## 4.5 "At the admins site".

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 !!!!

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.

### (old sendmail) add some lines to sendmail.cf

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).

> `(*** < file > *** add ***) /etc/sendmail.cf`

> `

>     # 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 . >

> `

### (new sendmail) Adding some lines to sendmail.cf

With the newer sendmail releases (tested with sendmail v8.8.7, 8.8.8). Ignore method A, and add the next lines ...

> `(*** < file > *** add ***) /etc/sendmail.cf`

> `

>     # Database of handled domains

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

>     *OR*

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

> `

### (new sendmail)editing the /etc/sendmail.cw (or /yourdir/sendmail.cw) file

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).

> `(*** < file > *** text ***) /etc/sendmail.cw`

> `

>     mydomain.dom            mailservice

> `

### creating a /etc/maildomains file

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 :)

With the OLDER sendmail versions:

> `(*** < file > *** text ***) /etc/maildomains`

> `

>     mydomain.dom            mailservice

> `

With the NEWER sendmail versions:

> `(*** < file > *** text ***) /etc/maildomains`

> `

>     @mydomain.dom           mailservice

> `

### let it work !

With the old & new sendmail versionsyou need to generate the btree (database) files, you'll need to do the following:

    cd /etc    (or /yourhomedir)
    makemap btree maildomains < maildomains

after that, kill the sendmail daemon, and restart it. it should now WORK! good luck :)

Next Previous Contents