Home

Search this site:
 

Horshack’s
very
own site

 

This is Bavaria, Germany!
You will find links to Perl,
bootdisks for system administration,
a lot of Linux,
Windows administration
and some personal belongings.
Linux security: mail, sendmail, fetchmail, procmail...

Linux mail, sendmail, uucp.
How to configure it fast, some samples, books

Table of contents:

 

Fetchmail

Fetchmail gets my mail from several POP-servers every 10 minutes or so. I start fetchmail from /etc/ppp/ip-up.local which runs after my dialup-connection has established:

# fetchmail gets my mail from several pop-accounts 
# every 10 minutes logger $0 starting fetchmail daemon /usr/bin/fetchmail -d 600 &

The configuration is in ~root/.fetchmailrc

# test this file with: fetchmail -a -v
# flush means: drop messages after getting it
set syslog
poll pop.gmx.de
proto POP3
user "juhei@gmx.de" password "xx1" to horshack flush

set syslog
poll mail.franken.de
proto POP3
user "juhei23" password "xx2" to horshack flush

set syslog
poll post.strato.de
proto POP3
user "ju.know%mydom.de" password "xx3" to horshack flush

set syslog
poll pop.t-online.de
proto POP3
user "juton" password "dontcare" to horshack flush

I stop fetchmail in /etc/ppp/ip-down.local like this:

# kill fetchmail
/usr/bin/fetchmail -q

 

 

Sendmail: compiling 8.12.1

Compiling sendmail 8.12.1 did not work for me, it stopped with a strange error-message in Redhat 7.2. Problem: did not find db3-database-libraries (db3*rpm). Solve: create file /usr/src/sendmail/devtools/Site/site.config.m4 with this line:

I also had to do this manually:

Mimedefang could not find libmilter (I couldn't find libmilter.a), I had to do this:

 

Sendmail: configure - go

A good book which kills your fear from it: Linux Sendmail Administration by Craig Hunt, publisher is Sybex International from March 22, 2001, ISBN: 0782127371 (Amazon.com link)

Some hints for configuring sendmail are here, after sendmail.mc you will find this files from /etc/mail: aliases, access, domaintable, genericstable, local-host-names, mailertable, trusted-users, virtusertable. At last there is my /etc/mail/Makefile to create all the databasefiles.

1. Never, never, never create your config with sendmail.cf which is cryptic. Always use sendmail.mc which is somewhere on your harddisk in ..../cf/cf/sendmail.mc, use the filename sendmail.mc and not another one, this is mine:

divert(-1)dnl
cf/cf/sendmail.mc for server
internal name: gatekeeper.rosi13.de (not in use in the internet)
external name: xxx.dip.t-dialin.net (changes frequently because 24x7 dialup)
v1, init
divert(0)dnl
dnl
dnl always add this
include(`../m4/cf.m4')
dnl version-id in the sendmail.cf-file
VERSIONID(`gatekeeper.mc, v1')
dnl to include ../ostype/linux.m4
OSTYPE(linux)dnl
dnl aliases-database defines where to put mail which is address
dnl to special recipients, e.g. root -> lippmann@gatekeeper.rosi13.de
dnl this file has to be made to a database file like this:
dnl cd /etc/mail; makemap -f hash aliases < aliases
dnl which creates a file aliases.db
define(`ALIAS_FILE',`/etc/mail/aliases')dnl
dnl
dnl always add a domain to sender-address in the mail
dnl also if mail is delivered only locally, you need this if you
dnl want to rewrite sender-addresses with genericstable
FEATURE(`always_add_domain')dnl
dnl
dnl the fully qualified servername is only a local domain
dnl which cannot be resolved in the internet, define a valid one
dnl lisa.franken.de is an official name which I can use
define(`confDOMAIN_NAME', `lisa.franken.de')dnl
dnl
dnl Rewrite internal domain-name in the mail-headers
FEATURE(masquerade_envelope)dnl
dnl
dnl file /etc/mail/local-host-names (cw_file -> the variable cw is set here
dnl internally). this file is not a database-file, only plain text,
dnl it contains all hostnames this server is called
FEATURE(use_cw_file)dnl
dnl
dnl file /etc/mail/access (make it a db-file with makemap... see above)
dnl determines for which domains we accept mail independent from the sender
dnl address (also RELAYing). this looks like this here:
dnl localhost                       RELAY
dnl 127.0.0.1                       RELAY
dnl rosi13.de                       RELAY
dnl sprachtheorie.de                RELAY
dnl because I use mail-addresses from all this domains
FEATURE(`access_db',`hash -o /etc/mail/access')dnl
dnl
dnl for rewriting the senderaddresses in the mails
dnl e.g. making accepted real-world-domainnames from internal domainnames
dnl this file looks like this:
dnl     horshack           horshack@lisa.franken.de
dnl     root               horshack@lisa.franken.de
FEATURE(`genericstable',`hash -o /etc/mail/genericstable')dnl
dnl my internal domain
GENERICS_DOMAIN(`gatekeeper.rosi13.de')dnl
dnl
dnl I don't know exactly what this is for:
FEATURE(`generics_entire_domain')dnl
dnl
dnl t-online does not accept mails routed to the server told
dnl by mx-records, so I have to reroute mails for this domain
dnl this file looks like this:
dnl     t-online.de     esmtp:smtp.t-online.de
dnl hash-file (look above in aliases):
FEATURE(`mailertable',`hash -o /etc/mail/mailertable')dnl
dnl
dnl more and more people send mails with senderaddresses like this
dnl in mailinglists: x@nospam.nono
FEATURE(`accept_unresolvable_domains')dnl
dnl
dnl include local mail-delivery and smtp:
MAILER(local)dnl
MAILER(smtp)dnl
dnl
dnl this is needed for mimedefang only
dnl mimedefang filters mailattachments by mimetypes (deny .exe, .dll, .scr...)
INPUT_MAIL_FILTER(`mimedefang', `S=unix:/var/run/mimedefang.sock, F=T, T=S:60s;R:60s;E:5m')
dnl wait 12h before sending warnmails about delivery because my mailserver
dnl is offline the whole night

define(`confTO_QUEUEWARN', `12h')dnl 

Build sendmail.cf and activate it by making this:

[root@gatekeeper sendmail-8.12.1]# cd cf/cf
[root@gatekeeper cf]# sh Build sendmail.cf
Using M4=/usr/bin/m4
rm -f sendmail.cf
/usr/bin/m4 ../m4/cf.m4 sendmail.mc > sendmail.cf || ( rm -f sendmail.cf && exit 1 )
chmod 444 sendmail.cf
[root@gatekeeper cf]# make install-cf
../../devtools/bin/install.sh -c -o root -g bin -m 0444 sendmail.cf /etc/mail/sendmail.cf
../../devtools/bin/install.sh -c -o root -g bin -m 0444 submit.cf /etc/mail/submit.cf
[root@gatekeeper cf]# /etc/rc.d/init.d/sendmail stop
Shutting down sendmail:                                    [  OK  ]
Shutting down mimedefang:                                  [  OK  ]
[root@gatekeeper cf]# /etc/rc.d/init.d/sendmail start
Starting mimedefang:                                       [  OK  ]
Starting sendmail:                                         [  OK  ]

Here are the database-files needed for sendmail to operate with this configuration:

2. File /etc/mail/aliases:

# Basic system aliases -- these MUST be present.
mailer-daemon:  postmaster
postmaster:     root
# General redirections for pseudo accounts.
bin:            root
# Person who should get root's mail
root:           horshack

3. File /etc/mail/access:

# by default we allow relaying from localhost...
localhost                       RELAY
127.0.0.1                       RELAY
rosi13.de                       RELAY
sprachtheorie.de                RELAY
lisa.franken.de                 RELAY
gmx.de                          RELAY
10.1.1.2                        RELAY

4. File /etc/mail/domaintable is empty

5. File /etc/mail/genericstable

horshack           horshack@lisa.franken.de
root               richard.lippmann@sprachtheorie.de
lippmann           richard.lippmann@sprachtheorie.de
# local user zirndorf has this address as sender (my office-address):
zirndorf           lippmann@zirndorf.de

6. File /etc/mail/local-host-names

# local-host-names - include all aliases for your machine here.
lisa.franken.de
gatekeeper.rosi13.de
rosi13.de

7. File /etc/mail/mailertable

# t-online does not accept mails routed to the server told
# by mx-records, so I have to reroute mails for this domain
# this file looks like this:
t-online.de     esmtp:smtp.t-online.de

8. File /etc/mail/trusted-users

# trusted-users - users that can send mail as others without a warning
# apache, mailman, majordomo, uucp, are good candidates

9. File /etc/mail/virtusertable is empty

10. File /etc/mail/Makefile to create all the database-files from plaintext for sendmail:

# These could be used by sendmail, but are not part of the default install.
# To use them you will have to generate your own sendmail.cf with
#  FEATURE('whatever')
#
POSSIBLE += $(shell test -f bitdomain     && echo     bitdomain.db)
POSSIBLE += $(shell test -f uudomain      && echo      uudomain.db)
POSSIBLE += $(shell test -f genericstable && echo genericstable.db)

all: ${POSSIBLE} virtusertable.db access.db domaintable.db mailertable.db aliases.db
virtusertable.db : virtusertable
        @makemap -f hash $@ < $<
userdb.db : userdb
        @makemap -f hash $@ < $<
 %.db : %
        @makemap hash $@ < $<
clean:
        @rm -f *.db *~

Use it like this: cd /etc/mail; make to create all databasefiles new.

 Sendmail, tricks and hints

1. Simply masquerade all users in one domain:

dnl add domainname to mailaddresses always, also in internal mails
FEATURE(`always_add_domain')
dnl Rewrite all internal addresses from internal.company.int to official.com
MASQUERADE_AS(official.com)
MASQUERADE_DOMAIN(internal.company.int)
FEATURE(`masquerade_envelope')

2. UUCP-Mailing

dnl No sizelimit for uucp-mails
define(`UUCP_MAILER_MAX', `0') 
dnl put all external mail to our smart-host flymail (this is the uucp-name of the remote host)
dnl You must be able to do this: uucico -S flymail
define(`SMART_HOST', uucp-dom:flymail)
dnl and later:
MAILER(`local')
MAILER(`smtp')
MAILER(`uucp')

More uucp-hints in http://www.psg.com/~brian/doc/comms/uucp.htm

3. Relay mail only by a from-line

This is dangerous (everyone can fake a from-address) but sometimes needed. When you like to relay mail independent from ip-addresses, smtpafterpop or whatever you can relay EVERY mail which contains a certain from-line. Insert this into the file /etc/mail/access:

# accept and relay _ALL_ mails which have this from-line in their
# headers, this is dangerous and can be exploited
From:mrgoodone@lisa.com RELAY

This must be activated like this in sendmail.mc

dnl don't care from which ip-address these mails come
dnl the only proof is the right from-address in the header
dnl this needs extra lines in /etc/mail/access: From:mrgoodone@lisa.com  RELAY
FEATURE(`delay_checks')dnl
FEATURE(`relay_mail_from')dnl

 

Sendmail, how to check the rules

Where will mail to special recipients will be delivered?
[root@gatekeeper cf]# sendmail -bv h@texas.net
h@lisa.texas.net... deliverable: mailer relay, host smtprelay.t-online.de, user h@lisa.texas.net
[root@gatekeeper cf]# sendmail -bv h@gatekeeper.rosi13.de <<== local mail address
h@gatekeeper.rosi13.de... User unknown
[root@gatekeeper cf]# sendmail -bv horshack@gatekeeper.rosi13.de
"|/home/horshack/bin/forward.pl"... deliverable: mailer prog, user |/home/horshack/bin/forward.pl
\horshack... deliverable: mailer local, user \horshack

 

Sendmail, commandline magic

sendmail -q Try to deliver messages in the sending-queue
sendmail -q -O Timeout.queuereturn=0 Ditto, but bounce the messages that can't be sent immediately:
sendmail -q -O Timeout.queuereturn=now Bounce all messages without even trying to send them
sendmail -L sm-msp-queue -Ac -q  Try to deliver messages in the local queue after uucp
rm /var/spool/mqueue/* Bounce all messages without even trying to send them
sendmail -bp

Shows what's in the sending-queue in the moment

[root@glosmitsoos mqueue]# sendmail -bp
/var/spool/mqueue (1 request)
-----Q-ID----- --Size-- -----Q-Time-----------------Sender/Recipient-----------
g437F9po026335 438 Fri May 3 09:15 <raab@zirndorf.de>
(host map: lookup (hugo-knoedler.de): deferred)
<info@hugo-knoedler.de>
Total requests: 1

 

Which mimedefang did work with this mail?

Mimedefang adds a header to the mails it works with:

X-Scanned-By: MIMEDefang 2.2 (www dot roaringpenguin dot com slash mimedefang)

But there are some Mimedefangs installed in my environment. I wanted to know which mimedefang was working with this mail like that:

X-Scanned-By: MIMEDefang 2.2 from lisa.d.franken.de

I had to change this line in mimedefang.c, make, make install, /etc/rc.d/init.d/sendmail restart:

#define SCAN_BODY \
"MIMEDefang " VERSION " (www dot roaringpenguin dot com slash mimedefang)"

 

Spam with mimedefang, filtering mails

http://www.roaringpenguin.com/mimedefang/ filters out types of files or MIME-attachments together with Sendmail 8.1.12 or newer (milter). The work to compile sendmail on your own and to install this software is worth it. Nearly everything gets filtered here with Mimedefang if attachments are on mails.

Mimedefang is great! You can configure it through a perlscript called /etc/mail/mimedefang, I use to have something like this (usually the sub "filter" is empty after installation):

sub filter_begin {
        # Never change mail for the administrator
        # this is a danger! Because ONE the recipients could be
        # mimedefang-admin and the other ones innocent people!
        foreach (@Recipients) {
                if (/$Administrator/i ) {
                        # Mail to administrator of mimedefang will not get filtered
                        $header = "X-mimedefang-gatekeeper.rosi13.de";
                        $header_content = "never touch mimedefang-admins mail (sub filter_begin)";
                        return action_add_header($header,$header_content);
                }
        }

        # Part to scan Sender
        $_ = lc($Sender);
        if (
                (/americanporno/) or
                (/sex/) or
                (/porno/) or
                (/suck/) or
                (/\@perfectmail.com/) or
                (/H27908\@terra.com.co/) or
                # always last line:
                (0 == 1) ) {
                        $header = "X-mimedefang-gatekeeper.rosi13.de";
                        $header_content = "gatekeeper_says_this_is_SPAMSPAMSPAMSPAM";
                        return action_add_header($header,$header_content);
        }

        # Part to scan subjects
        if (open(HDRS,"<./HEADERS")) {
                while (<HDRS>) {
                        #
                        # Part to scan subjects
                        #
                        if (/^subject: (.+)/i) {
                                $_ = lc($_);
                                $header = "X-mimedefang-gatekeeper.rosi13.de";
                                $header_content = "gatekeeper_says_this_is_SPAMSPAMSPAMSPAM";
                                if (
                                        (/\?{4,}/) or
                                        (/anal/) or
                                        # "ass" but no password
                                        (/\bass/) or
                                        (/boost/) or
                                        (/horny/) or
                                        (/    \s+(\d{4,})/) or
                                        (/sex/) or
                                        (/suckin/) or
                                        (/xxx/) or
                                        (/make \$/) or
                                        (/low cost/) or
                                        (/fukia/) or
                                        (/double your money/) or
                                        # always last line:
                                        (0 == 1) ) {
                                        return action_add_header($header,$header_content);
                                }
                        }
                }
                close HDRS;
        }
}

Mails to the administrator-user shall be untouched:

sub filter {
    my($entity, $fname, $ext, $type) = @_;
    # Check aditionally for a recipient which gets not filtered
    foreach (@Recipients) {
          if (/$Administrator/i ) {
                 # Mail to administrator of mimedefang will not get filtered
                 $header = "X-mimedefang-gatekeeper.rosi13.de";
                 $header_content = "never touch mimedefang-admins mail (sub filter)";
                 return action_add_header($header,$header_content);
        }
    }
    if (re_match_ext($entity, '^\.(exe|com|bat|vbs|scr|shs|dll|vxd|pif|reg|ocx|lnk|ini)$')) {
        return action_quarantine($entity, "An attachment named $fname was removed from this " .
          "document as it\nconstituted a security hazard.  If you require this document, " . 
          "please contact\nthe sender and arrange an alternate means of receiving it.\n");
    }
    return action_accept();
}

But there is more you can do. Bounce mails (including a reason why):

This is made simply by checking sender and recipients:

sub filter {
    my($entity, $fname, $ext, $type) = @_;

    # extension by Richard Lippmann, 25.6.2002
    # rejection of repeated virus-senders by from-line
    # (information about fields from file mimedefang.pl)
    # Sender of mail is in $Sender
    # Recipients of mail are in @Recipients
    #
    # we don't like ANY message from these from-addresses
    my %bounce = (
        # section virusspreader
        "virusspreader" => {
                sender => [ qw(
                        virussender1985@t-online.de
                        ) ],
                message => "Mail rejected because repeated virusspreading ",
                action => "bounce",
        },
        # section spammer
        "spammer" => {
                sender => [ qw(
                        infomail@gmx.de
                        ) ],
                message => "Mail rejected because repeated spamming ",
                action => "bounce",
        },
    );
    foreach my $reason (keys %bounce) {
        foreach my $badfrom ( @{$bounce{$reason}->{sender}} ) {
                if ($Sender =~ /$badfrom/i) {
                        # discard or bounce message
                        return action_bounce($bounce{$reason}->{message})
                                if ($bounce{$reason}->{action} eq "bounce");
                        return action_discard()
                                if ($bounce{$reason}->{action} eq "discard");
                }
        }
    };
    # messages from single mailadresses to single mailadresses
    # which we don't like (mailings from companies which want to "inform"...
    my %one2one = (
        # mails from lists or so to reject
        "nr1" => {
                sender => 'lippmann@sprachtheorie.de',
                recipient => 'lippmann@zirndorf.de',
                message => "Please don't send me mails ",
                # action can be "bounce" or "discard"
                action => "bounce",
        },
    );

    foreach my $reason (keys %one2one) {
        foreach my $rec (@Recipients) {
                # there are < and > in the recipients address
                $rec =~ s/\<//g;
                $rec =~ s/\>//g;
                if (($Sender =~ /$one2one{$reason}->{sender}/i)
                        and ($rec =~ /$one2one{$reason}->{recipient}/i) ) {
                        # discard or bounce message
                        return action_bounce($one2one{$reason}->{message})
                                if ($one2one{$reason}->{action} eq "bounce");
                        return action_discard()
                                if ($one2one{$reason}->{action} eq "discard");
                }
        }
    };
    #
    # End of expansion
    #
...

 

Starting and stopping mimedefang with sendmail

You have to start mimedefang together with sendmail when your systems start. I do it like this:

start() {
        # Start daemons.
        #
        # To delete dangerous attachments: mimedefang
        rm -f /var/run/mimedefang.sock
        echo -n "Starting mimedefang: "
        daemon /usr/local/bin/mimedefang -n $MAX_CONCURRENT_FILTERS \
-p /var/run/mimedefang.sock RETVAL=$? echo [ $RETVAL -eq 0 ] || exit 1 # starting sendmail itself echo -n $"Starting $prog: " /usr/bin/newaliases > /dev/null 2>&1 if test -x /usr/bin/make -a -f /etc/mail/Makefile ; then make -C /etc/mail -q else for i in virtusertable access domaintable mailertable ; do if [ -f /etc/mail/$i ] ; then makemap hash /etc/mail/$i < /etc/mail/$i fi done fi daemon /usr/sbin/sendmail $([ "$DAEMON" = yes ] && echo -bd) \
$([ -n "$QUEUE" ] && echo -q$QUEUE) RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sendmail return $RETVAL } stop() { # Stop daemons. echo -n $"Shutting down $prog: " killproc sendmail RETVAL=$? echo echo -n "Shutting down mimedefang: " killproc mimedefang echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sendmail return $RETVAL }

 

Spamassassin

I want to change the recipient of spam-mails. Spam-mails shall not go to the user but to a special mail-account which is for spam only. The right place is /etc/mail/mimedefang-filter to do this:

sub filter_end {

......


                # Delete all Recipients from Spammail and send these mails

                # to a special user in our domain

                my $towhom_msg;

                foreach my $rec (@Recipients) {

                        md_log("Remove recipient $rec");

                        $towhom_msg .= "This mail should have been sent to: $rec\n";

                        delete_recipient($rec);

                }

                add_recipient("spam\@mydomain.com");

                # Add a file which shows to whom this mail should have been gone

                action_add_part($entity, "text/plain", "-suggest",

                                "$towhom_msg\n",

                                "to_whom_this_mail_was_formerly_addressed.txt", "inline");

                # end of redirecting spam-mails

 

Sending automatic reply-mails

You can do this by checking e-mails automatically. I decided:

1. to get my e-mails
2. to let them check additionally

Create a file .forward in your homedirectory like this for a user wwwrun which shall get mails from persons with a special headline:

\wwwrun,"| /home/wwwrun/forward.pl"

This means that the mail gets delivered to the user himself AND to the programm mentioned. The program forward.pl is not too sophisticated:

#!/usr/bin/perl
# file ~/forward.pl
# called by ~/.forward which looks like this for user wwwrun:
# wwwrun,"| /home/wwwrun/forward.pl"
#
# mission: generate automatic mails as answers
#
BEGIN {
        use lib "/usr/local/bin/hor.module";
}
use mailhor;
# This is valid for all mails generated here:
my $smtpserver = "gatekeeper.rosi13.de";
my $from = 'wwwrun@gatekeeper.rosi13.de';
# my $cc = 'horshack@gatekeeper.rosi13.de';
my $cc = '';

# Parse this mail:
my ($org_subject,$org_from,$org_replyto) = (undef,undef,undef);
my @mail = <STDIN>;
foreach (@mail) {
        $org_subject = $1 if (/^Subject: (.*)$/i);
        $org_from = $1 if (/^From: (.*)$/i);
        $org_replyto = $1 if (/^Reply-To: (.*)$/i);
}
# Analyze
if ($org_subject =~ /please give me password for msdos-bootdisk/) {
        &send_disk_password(to=>$org_from,cc=>$cc);
        system "logger \'sending dos-password-mail to $org_from\'";
}
exit;

sub send_disk_password {
        my (%args) = @_;
        my $to = $args{to};
        my $cc = $args{cc};
        my $subject = "Re: please give me password for msdos-bootdisk";
        my $body =<<'EODISKPASSWORD';
Hi,
thanks for your interest... blablabla.
From Nuernberg, Bavaria
yours
Richard Lippmann
EODISKPASSWORD
        &mailhor::sendamail(smtpserver=>$smtpserver,from=>$from,
            to=>$to,cc=>$cc,subject=>$subject,body=>$body);
}
 

Sorting mail from mailinglists
to a special mailfolder with UW imap

1. My .procmailrc
2. How to test a new .procmailrc

1. My .procmailrc

UW Imap 2000 is an IMAPD which is very easy to install. A little problem is that procmail needs a special program dmail (look for imap-tools) to deliver mails not to the usual inbox (/var/spool/mail/username) but to a special subfolder (~/mail/perllist).

I use procmail to sort mails:

# ~horshack/.procrc
# Version 0.02
#
# Log all actions to this file, this directory must exist
# and be writable by the user himself:
LOGFILE=$HOME/syslog/procrc.log
VERBOSE=on
LOGABSTRACT=off
EXITCODE=

# Mail _to_ (or cc, resent whatever) _OR_ ( * 1^0 )
# -> deliver to mail/perl_win32
:0:
* 1^0 ^TO_activeperl@listserv\.activestate\.com
* 1^0 ^TO_perl-win32-admin@listserv\.activestate\.com
|/usr/local/bin/dmail +mail/perl_win32

# Mails which contain a header from my program mimedefang
# which does some spam-checking by itself
:0:
* ^X-mimedefang-gatekeeper.rosi13.de:.*SPAMSPAMSPAMSPAM
|/usr/local/bin/dmail +mail/spam

# Mails _from_ the address kitamaster@kita-bayern.de
# AND with a special subject
# -> move to mail/kita
:0:
* ^From: kitamaster@kita-bayern\.de
* ^Subject: kita\.pl, WWW-Aenderung.*
|/usr/local/bin/dmail +mail/kita

# Spam by subject OR subject OR subject OR subject
#       * 1^0 condition1
#       * 1^0 condition2
#       This works best, better than \|
# -> move to mail/spam
:0:
* 1^0 ^Subject: .*cocks
* 1^0 ^Subject: .*horny
* 1^0 ^Subject: .*sex
|/usr/local/bin/dmail +mail/spam

# Default, deliver mail to recipient
:0:
|/usr/local/bin/dmail

2. How to test a new .procmailrc

First create a directory ~/procmailtest which you own and put a testmail in a file spam.msg including all headers:

From: a fried <spammer@nowhere.com>
Message-Id: <200202241157.g1OBvoaA020169@gatekeeper.rosi13.de>
Subject: Horny teens!
To: me@somewhere.com (Richard Lippmann)
Date: Sun, 24 Feb 2002 12:57:50 +0100 (CET)
X-Mailer: ELM [version 2.5 PL6]
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Try this website! http://www.whoknows.com
A friend...

Now create a new file ~/procmailtest/ptest.rc in which you try out a new filterrule. Also create ~/syslog/ for the logfiles which are created while testing the rules:

# ~horshack/procmailtest/ptest.rc
# Version 0.03-test
#
# Log all actions to this file, this directory must exist
# and be writable by the user himself:
LOGFILE=$HOME/syslog/procrc.log
VERBOSE=on
LOGABSTRACT=off
EXITCODE=

# Spam by subject OR subject OR subject OR subject
#       * 1^0 condition1
#       * 1^0 condition2
#       This works best, better than \|
# -> move to mail/spam
:0:
* 1^0 ^Subject: .*cocks
* 1^0 ^Subject: .*horny
* 1^0 ^Subject: .*sex
|/usr/local/bin/dmail +mail/spam

# Default, deliver mail to recipient
:0:
|/usr/local/bin/dmail

Let it run:

[horshack@gatekeeper]$ cd ~procmailtest

[horshack@gatekeeper procmailtest]$ ls -l
-rw-rw----    1 horshack wheel         559 Feb 25 16:59 ptest.rc
-rw-rw----    1 horshack horshack      386 Feb 25 16:58 spam.msg

[horshack@gatekeeper procmailtest]$ cat spam.msg | procmail ~/procmailtest/ptest.rc

You can find what procmail did in the file mentioned in the line LOGFILE=$HOME/syslog/procrc.log

[horshack@gatekeeper]$ cat ~syslog/procrc.log

procmail: [4681] Mon Feb 25 17:00:19 2002
procmail: Assigning "LOGABSTRACT=off"
procmail: Assigning "EXITCODE="
procmail: Score:       0       0 "^Subject: .*cocks"
procmail: Score:       1       1 "^Subject: .*horny"
procmail: Score:       0       1 "^Subject: .*sex"
procmail: Couldn't determine implicit lockfile from "/usr/local/bin/dmail"
procmail: Locking ".lock"
procmail: Executing "/usr/local/bin/dmail,+mail/spam"
delivered to /home/horshack/mail/spam
procmail: Assigning "LASTFOLDER=/usr/local/bin/dmail +mail/spam"
procmail: Unlocking ".lock"
procmail: Notified comsat: "horshack@:/usr/local/bin/dmail +mail/spam"

It seems that it worked :-)

 

Misc Mailing Issues 

How to send mail automatically with attachments? You can easily send mail with elm like that:

#!/bin/sh
echo "This is $0"
if [ -z $1 ]
then
        echo "usage: $0 filename"
        exit
fi
to="you@somewhere.com"
filename=$1
if [ -e $filename ]
then
        echo "Sende Mail mit $filename an $to"
        uuencode $filename $filename | elm $to -s "$filename"
        echo "delete file $filename"
        rm $filename
else
        echo "Sending Mail that file $filename is not there to $to"
        echo "Could not send file $filename" | elm $to -s "Problem sending a file"
fi
exit

 

Impressum