Drupal Mailhandler Tutorial

This is an overview of my work with Drupal's Mailhandler module, designed to allow content creation on a Drupal (or CivicSpace)site via email. If we combine this functionality with a mailing list address that's authorized to post content, we have the first steps towards an integrated forum and mailing list system (the next stage would be to develop a system that automatically emails any created content to the mailing list address).

Mailhandler requires PHP IMAP enabled on the server hosting your site. It won't work without it...trust me, we've tried. The current implementation of Direct Admin, nicknamed Dovecot, doesn't support a clear PHP IMAP implementation as far as I know, and our efforts to get a working server under Direct Admin with our current hosting company have so far been unsuccessful, though we do have a working implementation on another server.

Once we found a server that has PHP IMAP enabled, I used Direct Admin to create an email account to be used solely by the site. (Later, I'll subscribe this email account to the listserv.) Then I installed mailhandler by uploading the module to the right directory for Drupal, and running the SQL script in phpMyAdmin (the standard installation process for all modules).

Then I went to Admin -> Modules to enable MailHandler, and then Admin -> Mailhandler to configure it. I clicked on the "add mailbox" tab to tell Drupal which email address to use.

Enter the username and password for the email account you just created. I chose POP for email format. I left Folder = INBOX, and left port = 110. I also had security disabled, error replies enabled (I'll remove this in the production phase, when I know it works), from header = sender, disabled cron, checked the box to delete messages after they are processed, and set input format = filtered html (not sure why this last setting is important, since I'll be overriding it with my command strings).

If you've been following along, you'll notice I left out the command arguments. That's because there are a lot of options, they're not well documented, and it's hard to figure them out...though they really make or break this process. I used:

type: page
taxonomy: [Community Technology]
promote: 1
status: 1
format: 3

This takes incoming content sent to that email address and turns them into pages, assigns the taxonomy term "Community Technology" to them, promotes them to the front page, and publishes them, allowing full HTML format. You can set publish: 0 to keep things from publishing if you're working on a live site, or promote: 0 to just keep it from showing up on the front page. If you do either of these, you'll have to visit your Administer Content section to see if your test post worked or not.

That's pretty much it for the test setup. Now you should fire up your email client and send a test email to the address you created, and then go to Admin -> Mailhandler and click the "retrieve" link next to that mailbox. If all went well, it should successfully grab your test email and insert it as content.

There are other ways to implement this. Incoming content can be inserted as forum posts, or as blog posts. Once you have a working model, you'll want to change the MailHandler setting to allow it to check email with every chron run, which will automate the process. You'll also want to turn error reporting off, or every error will end up being sent back to the mailing list. Lastly, you'll want to sign up for the mailing list in question with the email address you used for MailHandler.

Since you can choose a folder to check other than "INBOX" in MailHandler, it's possible to have this work with your current email account. Just create a filter to send all mailing list postings to one specific online folder, and have MailHandler only check that folder. If you use Thunderbird with IMAP, you could do this fairly easily...or use it as an online folder where every email you moved in was automatically added to your site as a page.

I'd recommend using the commands section to tag everything that comes in with a unique taxonomy term. This'll let you provide a navigation link on your site that says something like "Archived Mailing List Posts" and points to the page for that taxonomy term.

I'm excited about the possibilities presented by this module...I think it goes a long way towards achieving true forum to listserv integration.

Comments

How do I know if I have PHP IMAP installed and working?

Is there a command I can use to find out if I have PHP IMAP installed and working on my site? If I don't have it, how do I get it?

Thanks

Dave