Mike Schilli's Friendly Neighborhood Perl Shop

Home
USArundbrief.com
Resume
CPAN Modules
Articles in English
Articles in German
Mike's Script Archive
English-Japanese Translation Trainer
Adventures with O'Reilly's Safari
10 Easy Steps to Become a California Driver
Unofficial perlmonks.com IRC Channel
My Collection of Outage Pages
Prisma (Computer Club Deutschland)
Mike's Monologues
Mike's Script Archive: LimitMail.pm

LimitMail -- Send mail, but limit the amount per user


NAME

    LimitMail -- Send mail, but limit the amount per user


DOWNLOAD

LimitMail.pm


SYNOPSIS

    use LimitMail;
    my $m = LimitMail->new();
    $m->mail({From    => 'from@from.com',
              To      => 'to@to.com',
              Subject => 'test mail',
             }, "Hey, there!");


DESCRIPTION

LimitMail sends out mail, but keeps track of the recipients and limits the number of mails they're getting.

Typical uses of LimitMail are applications sending out automatic notification emails. If a system goes berserk and keeps sending out emails, we don't want to fill up the user's mailbox. Instead, the first message should be sent and subsequent mail requests should be discarded until a selectable time period is over.

my $m = LimitMail->new()
This function takes a couple of optional parameters. If they're all omitted, they default to the following values:
    my $m = LimitMail->new(
        tracker_db     => "/tmp/limitmail",
        send_interval  => 3600 * 24,
        mailer_options => ['sendmail'],
    );

tracker_db specifies the base of the NDBM file which LimitMail uses internally as a persistent store for who got mail and when. It defaults to /tmp/limitmail, resulting in two NDBM files /tmp/limitmail.dir and /tmp/limitmail.pag.

send_interval specifies the time interval in which Limitmail will discard messages instead of sending them after a message has been submitted. It defaults to 3600 * 24 (one day).

mailer_options is a reference to an array, containing parameters which will be used by Limitmail internally to construct a Mail::Mailer object. Check the Mail::Mailer documentation for details. It defaults to ['sendmail'].

$m->mail($mailoptions, $body)
mail() triggers email to be sent out -- if the restrictions allow it. In $mailoptions, it takes a reference to a hash to the mail headers as Mail::Mailer expects them. Typical values are:
    { From    => 'from@from.com',
      To      => 'to@to.com',
      Cc      => 'cc@cc.com',
      Bcc     => 'bcc@bcc.com',
      Subject => 'my subject mail',
    }

$body holds the message of the mail to be sent out as a string, lines are devided by newlines.

$m->nuke_db()
Nukes the tracker DB. It won't delete the file(s), but will assign an empty list to the persistent hash.


LEGALESE

Copyright 2002 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.


AUTHOR

2002, Mike Schilli <m@perlmeister.com>


Latest update: 20-Oct-2013