Forum OpenACS Q&A: Email Autorespoder via AOLserver et.al.

Has anyone implemented an autoresponder with AOLserver / ACS / PG? We want to use this for a
Multi-day educational email course. to wit:

  • Student sends an email to xxx@yyy.com and gets the first day email
  • On days 2 thru 6 they get a different email each day.

I know there are commercial outfits that do this, some for free in return for junky ads at the bottom and some you pay for that have no ads. The benefit to having it as part of the ACS system is that we can easily track which of our members took the course and "spam" those that have NOT.

The most difficult challenge that I found was receiving email in AOLserver / PG. This is the first step necessary in doing an autoresponder. One thought is to have a timed module that polls a POP3 account for email.... OR.... something better?

TIA -Bob

Collapse
Posted by Don Baccus on
Dan's ported webmail, which grabs mail from qmail and stuffs it into PG.  That would be a place to start looking ...
Collapse
Posted by MaineBob OConnor on

A number of months back, we tried to implement qmail without success and Bill our sysadmin does NOT want to try this again. This is why we are interested in a POP3 solution.

If I can be convinced that qmail is "THE WAY" for OpenACS then I'll twist Bill's arm. 😊

Collapse
Posted by Don Baccus on
<shrug> you can probably get quite a bit of help from the web/db crowd, and Dan Wickerstrom might be willing to help, too.
Well, maybe if Bill spent one day carefully following installation instructions in Life with qmail, just like me, he would have qmail installed. Was it easy or enjoyable? No. Was it possible? Certainly yes.

From the engineering perspective I doubt writing a module to retrieve e-mail from POP3 (POP3 protocol is considered to be seriously brain-damaged) will be any easier than following a documentation to install a piece of software.

Collapse
Posted by Henry Minsky on
I wrote a perl script which still ships with ACS 3.4, which is
called q.pl or queue-message.pl. It's made to be called from
qmail or sendmail, and basically just stuffs the email message
into a queue table in  the database. You could probably easily modify it to stuff
into Postgres, since it uses the Perl DBI API.

it's documented a little bit in the ACS 3.4 documentation dir as
"email-handler".

Collapse
Posted by Henry Minsky on
#!/usr/local/bin/perl
#
# Respond to incoming mail message on STDIN
#
# hqm@ai.mit.edu
#
# This script does the following:
#
sub usage () {
    print '
  usage: queue_message.pl db_datasrc db_user db_passwd destaddr

  Inserts the data from stdin into a queue table.

  Assumes the following table and sequence are defined in the db:

    create table incoming_email_queue (
            id          integer primary key,
            destaddr    varchar(256),
            content             clob,           -- the entire raw message content
                                            -- including all headers
            arrival_time        date
    );

    create sequence incoming_email_queue_sequence;

';
}

use DBI;
#use Mail::Address;

use DBD::Oracle qw(:ora_types);

#need for archive file

use Time::localtime;
use IO::File;

################################################################
# Global Definitions

$db_datasrc        = shift;
$db_user           = shift;
$db_passwd         = shift;
$destaddr          = shift;

$DEBUG = 1;
$debug_logfile = "/tmp/intranet-mailhandler-log.txt"; # 

# Oracle access
$ENV{'ORACLE_HOME'} = "/ora8/m01/app/oracle/product/8.1.6";
$ENV{'ORACLE_BASE'} = "/ora8/m01/app/oracle";
$ENV{'ORACLE_SID'} = "ora8";

$archive_mail_directory = "/web/arsdigita/mail-archive";

if (!defined $db_datasrc) {
    $db_datasrc = 'dbi:Oracle:';
}

if (!defined $db_user) {
    usage();
    die("You must pass a db user in the command line");
}

if (!defined $db_passwd) {
    usage();
    die("You must pass a db passwd in the command line");
}



#################################################################
## Snarf down incoming msg on STDIN
#################################################################

while (<>) {
    $content .= $_; 
}


if ($DEBUG) {
    open (LOG, ">>$debug_logfile");
    debug("================================================================
");
    debug("Recevied content:
$content
");
    debug("================================================================
");
}

# save a clean copy in filesystem.

system("chmod 666 $debug_logfile");

my $archive = open_archive_file();
$archive->print( $content );
$archive->close();

# Open the database connection.
$dbh = DBI->connect($db_datasrc, $db_user, $db_passwd)
  || die "Couldn't connect to database";
$dbh->{AutoCommit} = 1;
# This is supposed to make it possible to write large CLOBs

$dbh->{LongReadLen} = 2**20;   # 1 MB max message size 
$dbh->{LongTruncOk} = 0;   


debug("Status: inserting into email queue
");
$h = $dbh->prepare(qq[INSERT INTO incoming_email_queue (id, destaddr,  content, arrival_time) VALUES (incoming_email_queue_sequence.nextval, '$destaddr', ?, sysdate)]);


$h->bind_param(1, $content, { ora_type => ORA_CLOB, ora_field=>'content' });

if (!$h->execute) {
    die "Unable to open cursor:
" . $dbh->errstr;
}
$h->finish;

$dbh->disconnect;
debug("[closing log]
");
if ($DEBUG) { close LOG; }

sub debug () {
    my ($msg) = @_;
    print LOG $msg;
}

sub open_archive_file () { 
    my $fh;
    my $name;
    my $i = 0;
    my $tm = localtime;
    my $today = sprintf("/%04d%02d%02d:%02d:%02d:%02d.", ($tm->year + 1900), $tm->mon + 1, $tm->mday, $tm->hour, $tm->min, $tm->sec);

    do { $name = "$archive_mail_directory$today$destaddr.$i";
         $i++;
     } 
    until $fh = IO::File->new($name, O_RDWR|O_CREAT|O_EXCL);

    return $fh;
}