My Projects
Search Blog

Categories
Archives
Useful Links
Photo Albums
RSS

Powered by
BlogCFM v1.15

Vivio Technologies CFML Hosting
26 April 2006
Coldfusion and qmail-inject

If you're running a coldfusion server on a unix system with qmail installed, then maybe you, like me, have often wished you could just directly pump email into the qmail queue.

Unfortunately, I haven't figured out a way to simply use cfexecute to call qmail-inject, because you have to pipe output from one program to another.  For example:

cat /home/rick/mymessage.html | /var/qmail/bin/qmail-inject

cfexecute doesn't seem to like piping output.  It assumes that everything in the arguments parameter is an argument.

So what I've done is written a little perl script that takes the email message as an argument and passes it off to qmail-inject.

Here's the perl script, I call it "cfqmail.pl"

#!/usr/local/bin/perl

# define the location of the qmail-inject binary
$QMAIL = "/var/qmail/bin/qmail-inject";

# for testing purposes, I'd recommend creating a message
# here and running this script from the command line until
# you get it working...
$msg = $ARGV[0];

# open a pipe to the qmail binary and send the message
open(QMAIL, "|$QMAIL");
print QMAIL $msg;
close(QMAIL);

To use this, you just create a message in a variable, complete with headers, making sure to be as RFC Compliant as possible (ie, make sure to use a unique message id, etc), and then call cfexecute:

<cfsavecontent variable="message_content">To: Rick Root <rick@webworksllc.com>
From: Rick Root <rick@webworksllc.com>
Message-Id: <#CreateUUID()#@webworksllc.com>
Subject: Test Message

This is a test message.
</cfsavecontent>
<cfset args = arrayNew(1)>
<cfset args[1] = message_content>
<cfexecute name="#ExpandPath(".")#/spool/cfqmail.pl"
     arguments="#args#"
     outputfile="#ExpandPath(".")#/spool/send.log"/>

It's worth mentioning that the outputfile really doesn't do much because cfexecute overwrites the file each time... if you really wanted to do some logging, you'd probably want to modify the perl script

Posted by rickroot at 11:55 AM | Link | 0 comments
Subscription Options

You are not logged in, so your subscription status for this entry is unknown. You can login or register here.

No comments found.

Post a comment (login required)