Injecting incoming email

From Dreamwidth Notes
Revision as of 19:13, 12 September 2012 by Swaldman (Talk | contribs)

Jump to: navigation, search

This page describes how to make a Dreamwidth install think it is receiving incoming email without actually sending it email. This might be useful if you are testing features such as post-by-email in an environment that is not able to receive email - such as a Dreamhack.

First, prepare the email. The easiest way is to send an email to yourself from one account to another and save the resulting message, including all headers, and then edit what you need to edit. In some clients this will be via a "view source" or "view original" link, or similar. Note that sending mail from one gmail account to another does not provide all the headers that you need - the email needs to actually go out to the internet and back. In particular, anything without Return-path: will be dropped as spam.

Make sure that your email does not have any blank lines anywhere until the body. This includes blank lines before the start of the headers. If you did accidentally leave a blank line at the top and not notice, you might spend two and a half hours wondering why nothing worked. Ahem.

Anyway, save your email somewhere accessible from the Dreamwidth installation. I'll assume from here that it's in your home directory and that it's called email.txt.

Incoming email is processed by the incoming-email worker. Start this with

$LJHOME/bin/worker/incoming-email

on a spare terminal. This will run until stopped by Ctrl-C, without showing any output on the screen.

Then, using another terminal, you can inject your test message by

$LJHOME/bin/incoming-mail-inject.pl < ~/email.txt

Hopefully, everything worked! If you are debugging something in the email-handling code, remember that you will need to restart the incoming-email worker after you change things to make sure that it is running the latest code.

Things to check if your emails are not doing anything useful:

  • Make sure that posting by email is enabled at http://www.yourname.hack.dreamwidth.net/manage/settings/?cat=mobile, with a permitted sender and a PIN. Make sure that your From: header is the permitted sender, and that the PIN is featured in one of the allowed places. Unless you are testing what happens when it isn't ;-)
  • Make sure that your successive test emails do not have the same date. There's some code intended to do rate-limiting that will drop successive emails that have less than five minutes between their Date: headers. This may not matter if you are restarting the worker each time - I haven't checked.
  • For some maybe-useful diagnostics, try logging into your hack's System account and looking at http://www.yourname.hack.dreamwidth.net/admin/theschwartz