Beatitude - Scheduled Mailings

- NAME
- Description
- REQUIREMENTS

- Installation Difficulty: moderate

- Configuration
- Installation

- Setting up the script.
- Setting up Beatitude to check schedules to run.
- Testing

- Setting up the Cron/Scheduled Job
- Optional Fun Things
- Debugging
- FAQs
- History
- To Do
- COPYRIGHT

# NAME

Beatitude - A Scheduled Mailer for Dada Mail

# Description

Beatitude is a plugin for Dada Mail that allows you to compose email messages to be scheduled for sending in the future.

Highly configurable, messages themselves can be in PlainText, HTML or multipart/alternative and have an unlimited number of attachments. The message itself can be composed in the plugin itself, fetched from a file or from a webpage.

The schedules themselves can be anywhere from one minute to years into the future and can be repeated infinitely. Schedules also have many safegaurds to help send only new content; for example: if a scheduled mailing is created to send the contents of a URL once a day, it will only send that URL if the contents are different from the previous day.

# REQUIREMENTS

It's best to get all these requirements in order before you begin.

- Dada Mail 2.8.10

  Beatitude will not work in any version previous.

- Ability to set Cron Jobs.

  You need to be able to set scheduled tasks, or cron jobs to use Beatitude. If you don't know if you do have this feature available you, ask your sys admin.

- The Storable Module

  If you have perl 5.8, this should already be installed. If it's not, you can grab it here:

              http://search.cpan.org/~ams/Storable-2.08/

  and install it.

- A Command Line

  It really helps if you have ssh or telnet access to your hosting account. Testing would be much easier.

## Installation Difficulty: moderate

# Configuration

There's a few things you need to configure in this script, they're all at the top.

- Change the lib path

  You'll need to explicitly state where both the:

  - Absolute Path to the site-wide Perl libraries
  - Absolute Path of the local Dada Mail libraries

  This is because this script will be running in a different environment and from a different location than what you'd run it as, when you visit it in a web-browser. It's annoying, but one of the things you have to do when running a command line script via a cronjob.

  As an example: `use lib qw()` lines probably look like:

       use lib qw(
       /home/myaccount/www/cgi-bin/dada
       /home/myaccount/www/cgi-bin/dada/DADA/perllib

       /usr/local/lib/perl5/site_perl/5.8.0/mach
       /usr/local/lib/perl5/site_perl/5.8.0
       /usr/local/lib/perl5/site_perl
       /usr/local/lib/perl5/5.8.0/BSDPAN
       /usr/local/lib/perl5/5.8.0/mach
       /usr/local/lib/perl5/5.8.0
       );

  The first few lines:

       /home/myaccount/www/cgi-bin/dada
       /home/myaccount/www/cgi-bin/dada/DADA/perllib

      Are the B<Absolute Path of the local Dada Mail libraries>.

  /home/myaccount/www/cgi-bin/dada is the absolute path to where the, dada directory in your cgi-bin (as it may be obvious).

  /home/myaccount/www/cgi-bin/dada/DADA/perllib is a directory inside your dada directory. Most like if you can find that first line (), just tack on, ``/DADA/perllib'' and you've got the second line.

  If you don't know where your site-wide Perl libraries are, try running this via the command line:

       perl -e 'print $_ ."\n" foreach @INC';

  If you do not know how to run the above command, visit your Dada Mail in a web browser, log into your list and on the left hand menu and: click, About Dada Mail

  Under Script Information, click the, More... link and under the, Perl Library Locations, select each point that begins with a, ``/'' and use those as your site-wide path to your perl libraries.

As far as required changes, that's it. We'll get to interesting optional things further down the line.

# Installation

## Setting up the script.

Beatitude is both a command line script and a CGI script.

More specifically, as a CGI script, it's a Dada Mail plugin. To install the script, it's best to put the scheduled_mailings.pl file into the plugins directory inside the dada directory, which is itself in your cgi-bin. If that directory doesn't exist, it's safe to make it.

Once the scheduled_mailings.pl script is inside that directory, change it's permissions to, 755 and view it in your web browser.

If the installation was done correctly, You'll most likely see a screen that asks you to log into your list.

Add this entry to the $ADMIN_MENU Config.pm array ref:

     {
     -Title          => 'Scheduled Mailings',
     -Title_URL      => $PLUGIN_URL."/scheduled_mailings.pl",
     -Function       => 'scheduled_mailings',
     -Activated      => 1,
     },

It's possible that this has already been added to $ADMIN_MENU and all you would need to do is uncomment this entry. This adds a menu item for Beatitude in Dada Mail's List Control Panel.

## Setting up Beatitude to check schedules to run.

Since this program is also command line tool, you can execute it via a command line. Running Beatitude with the --run argument will have it check if any schedules should be run, and mail messages that need to be mailed.

     prompt>./scheduled_mailings.pl

I suggest before you do that, you test the scheduled_mailings.pl script.

## Testing

You can pass the --test argument to scheduled_mailings.pl to make sure everything is workings as it should. The --test argument does not take any arguments. If everything is set up correctly, you'll get back a verbose message of the going's on of the script:

     prompt>./scheduled_mailings.pl --test

     ------------------------------------------------------------------------
     Running Schedule For: mytestlist
     Current time is: June 26th 2003 - 5:25 pm
         No schedules to run.
     ------------------------------------------------------------------------

In this example, Beatitude checked schedules to be run for the 'mytestlist' list, found none, and exited. If there is a schedule to run, the output my look like this:

     ------------------------------------------------------------------------
     Running Schedule For: mytestlist
     Current time is: June 26th 2003 - 5:33 pm

         Examining Schedule: 'Justin's Test Schedule'
         'Justin's Test Schedule' is active -
             Schedule last checked:     June 26th 2003 - 5:31 pm
             Next mailing should be on: June 26th 2003 - 5:33 pm
                 'Justin's Test Schedule' scheduled to run now!
     ------------------------------------------------------------------------

# Setting up the Cron/Scheduled Job

You want to set this script to execute via a con or scheduled, job. Here's what a theoretical cron tab for this script may look like:

     0,30 * * * * /usr/bin/perl /home/myaccount/www/cgi-bin/dada/plugins/scheduled_mailings.pl >/dev/null 2>&1

This will run the script every half hour. You can run this script as often as you want, just be logical. I wouldn't run this script every five minutes, that's a bit overkill.

Different hosts may have a control panel to set up crontabs, my host gives me the pleasure of the contrab command. I type in:

     prompt> crontab -e

and am launched into my favorite text editor to type in the crontab.

# Optional Fun Things

There's a slew of optional arguments you can give to this script:

- --verbose

        prompt>./scheduled_mailings.pl --verbose

  passing the --verbose parameter is like giving this script some coffee. Similar to what you'd see if you ran the script using:

       prompt>./scheduled_mailings.pl --test

      But the scheduled mailings will actually get sent.

- --log

  If you pass a filename to the script it'll write a log entry that will look the same as what's outputted when you run with the --verbose flag.

  If you don't want to pass the log each time, you can set a log in the $Plugin_Config-{Log}> variable.

- --version

       prompt>./scheduled_mailings.pl --version

  WIll print out both the version of Beatitude and also of Dada Mail. Good for debugging. Looks like this:

       Beatitude version: .1
       Dada Mail version: 2.8.8

- --list ./scheduled_mailings.pl --list myslistshortname

  If you want to run schedules for only one list, you can pass the --list argument to scheduled_mailings.pl with a listshortname as its value.

# Debugging

Beatitude can be a bit difficult to set up, if you've never set up a similar script before. Here's a few things I do, to make sure a Beatitude install is working correctly:

First off, I install Beatitude, using the direction above.

Then, I'll make a test list, so if something goes wrong, no one will be affected. I won't add any subscribers, since it won't be necessary. Any test messages I send out will go to the list owner (me).

I'll then create a new schedule to send a message, every minute and repeat that schedule, indefinitely.

Then, I'll connect to the server via ssh, and run the command to run Beatitude, exactly as I would type the command in the crontab - except perhaps I'll put that --verbose flag on there, so I can see what's happening.

It takes a minute for the first message to be sent, and after that, every minute, if I run the command, I'll get a mailing. This will let me know that the schedules are firing correctly, and that I have the correct command to run Beatitude.

If that's working, I'll set the cronjob - and have it run every five minutes or so. I'll get some coffee.

I'll come back and if I have a few messages that I didn't send, I'll know the cronjob did its job.

# FAQs

- I keep getting, 'permission denied' errors, what's wrong?

  It's very possible that Beatitude can't read your subscription database or the list settings database. This is because Dada Mail may be running under the webserver's username, usually, nobody, and not what Mystery Girl is running under, usually your account username.

  You'll need to do a few things:

  - Change the permissions of the list subscription and settings databases

    You'll most likely need to change the permissions of these files to, '777'. PlainText subscription databases have the format of listshortname.list and are usually located where you set the $FILES Config file variable. .List settings Databases have the format of mj-listshortname and are usually located in the same location.

  - Change the $FILE_CHMOD variable

    So you don't need to change the permissions of the list files for every new list you create, set the $FILE_CMOD Config variable to 0777: $FILE_CHMOD = 0777; Notice there are no quotes around 0777.

- I found a bug in this program, what do I do?

  Report it to the bug tracker:

  http://sourceforge.net/tracker/?group_id=13002&atid=113002

- What's up with the name, Beatitude?

  Beatitude, in a historical context, refers to one of the eight sayings the Christian prophet, Jesus is believed to have said on the Sermon on the Mount. Each saying starts with, ``Blessed are the...'' - a similar saying over and over again, much like sending a similar message again and again

  It also means, ``a state of supreme happiness''.

  But to me, I think of Beatitude as almost a shorthand for, Beat Attitude; the Beat Generation being a group of writers whose inner circle included Jack Kerouac, Allen Ginsberg, William Bourroughs, Gregory Corso and many more.

  To Kerouac, ``Beat'' -- a shorthand term for ``beatitude'' and the idea that the downtrodden are saintly -- was not about politics but about spirituality and art. -Douglas Brinkley

  A modern Beatitude would be Ginsberg's Please Master, found in the book, Fall of America.

  The Beat Generation attempted to communicate the thoughts, ideas and adventures of their normal lives. I can only hope that communication with my Beatitude will be a tenth that incredible.

  My personal bookshelf is overflowing with books from the Beat Generation authors and one reason I moved to Boulder, CO, and then Denver, CO was because of the Denver adventures of Sal Paradise and Dean Moriarty in On The Road and to be close to the Jack Kerouac School of Disembodied Poets in Boulder, CO.

# History

- .6 8/25/04

  Very very small tweak to the log file routine - log file is chmod'd to the $FILE_CHMOD

- .5 12/27/03

  Archiving has been put in place, but only works if you have MIME-Tools installed. Given the nature of how messages are made, it's far easier to just rip apart a message already made, than try to remake it.

  Now that archiving works, Beatitude should play well with the Clickthru tracker. Grr!

  minor bugs fixed in regards of erroneous messages saying that the schedule was ended if the mailing schedule was indefinite.

- .4 - 12/07/03

  There was a slight issue with repeating schedules:

  Repeated schedules would not get sent if the schedule had never been checked before. Although a minor bug, it is rather annoying.

  This issue should be fixed.

- .3 - 11/23/03

  Minor tweaks.

- .2 - 7/2/03

  I noticed that the HTML admin template was printed twice when you send a test mailing in some instances. This has been fixed.

  There was a bug in the supporting libraries that affects repeating schedules. It's advised that if you run repeating schedules, that you upgrade to vesion 2.8.9 of Dada Mail.

- .1 - 6/26/03

  Initial Release for Mojo Mail, 2.8.8

# To Do

Look into ways to couple Beatitude with such apps as Blogger and Movable Type. (and if anyone who uses that sounds interested, let me know...)

# COPYRIGHT

Copyright (c) 1999 - 2008 Justin Simoni http://justinsimoni.com All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.