Warning: main(/home/thatbrad/www/v1mtrefsearch.php) [function.main]: failed to open stream: No such file or directory in /home/thatbrad/public_html/v1/archives/cat_movable_type.php on line 28
Warning: main() [function.include]: Failed opening '/home/thatbrad/www/v1mtrefsearch.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/thatbrad/public_html/v1/archives/cat_movable_type.php on line 28
post via email
so i wanted to be able to post to this blog via email. why? because it's possible, and because i wanted to be able to post random things here via email through my cell phone. there are several folks out there who have each written mt-plugins or hacks or scripts to get the job done.
- raffi krikorian @ wasted bits had a small script that seemed to be just what i wanted. the only downside to his was that you couldn't choose a category for the entry. you set up an email account to send your posts too and then pipe them through his nifty script. figuring out the piping was a bit of a chore but once i got past that it was a great script. except that i could never get it to work.
- ian barton @ ian-barton.com had another take on the subject. instead of piping the email through his script. it will just check a specified email account for messages and then it will do the posting from there. his didn't allow you to choose a category either though. and again, i couldn't get it to work
- david raynes @ rayners.org has a full fledged mt-plugin called mt-email. his had all the functionality i was looking for (choosing a category), with the additional feature of being able to post a comment to a previous entry. however, his required a bit more in the bit of technical knowledge, like how to add headers to an email.
raffi and ian's scripts are used by other folks. they do work. i just couldn't get them to. the fact that i ended up getting mt-email to work was nothing short of a miracle. i tinkered, i played, i learned. also, mt-email isn't working perfectly for me as of this point. i am able to post comments to past entries via email perfectly, however when i post a new entry via email my site doesn't rebuild. so the entry doesn't show up until i manually rebuild the site, or someone posts a comment or something that causes the site to rebuild.
first let's start with the little things about mt-email i learned along the way. then i'll share with you how i did the nifty header adding thingamajig that it requires.
- mt-email should be put in your main mt directory, not the plugins directory.
- the address on line 70 (which was actually on line 69 in my version) $return_addr should be the address to which you're going to be sending the blog entries. this may seem completely obvious to some..if so, move along.
- when you email your entries you must send them from an account that corresponds to an author in mt who has permission to post to that blog. again, it may seem obvious to you that that is the case, but my author email in mt is a spam account i don't send email from, so it took a scouring of the code to realize what mt-email was checking.
- the emailed post will have whatever "Post Status" is the default for that blog. so if you want it published as soon as you post it, you have to have the default post status for mt set to post.
ok, i think that takes care of the tricky parts, except for one and i'll explain it below. now, the whole headers thing. as i said in the beginning, i wanted to post random things here via my cell phone. mt-email requires certain things to be in the headers of your email messages (blog id, password, blog name, category). you can't add those to cell phone emails. i couldn't even figure out how to add them to messages sent via outlook. plus, as david mentions on his site, this is not secure. no less secure than logging into mt is already, but still not secure. enter procmail.
i don't know exactly what procmail is but it does something with your email. one of many things you can do with it is add headers to email messages. you can get around this mt-email requirement by hacking the script a bit and setting the required info up as variables, which in retrospect i probably should have done, or you can do it as i describe below.
you'll need shell access to your account for this next step. you need to edit a file called .rc.local.init . it was in my /home/username/domain-mail/ directory. it may not exist. if it doesn't then first you'll want to make sure .procmail, in the same directory, has this line at the top.
now open, or create or whatever you gotta do, .rc.local.init and add this
:0
* $RECIP ?? ^^account_you_send_entries_to@$DOMAIN
{
:0fhw
| formail -I "X-MT-Pass: password" \
-I "X-MT-Blog-Id: blogid" \
-I "X-MT-Category: primary category|secondary category"
:0
|/path/to/script/cgi-bin/mt/mt-email.pl
}
you can substitute "X-MT-Blog-Name: xxxx" for "X-MT-Blog-Id: blogid". don't have both.
now, when email goes to account_you_send_entries_to@$DOMAIN.COM they'll get those headers added to them and then get piped through mt-email and you haven't sent your password racing through the internet in plain text.
doing it this way you'll be stuck with those categories forever. i've opted out of including the category headers. i'm planning to hack the script a bit so that i can include something like <category>movable type</category> in my email message and the script finds that, cuts it out of the entry, and then sets that up as the category. if anyone else would like to do that, or if mr. raynes would like to add that functionality i'd be a huge fan.
also, since i'm posting via a cell phone, i'd rather not type "New Entry : xxxxx" when i want to post. i don't think my cell will allow that long of a subject. so if you'd like to change the indicator of a new entry to something like "n:" just edit line 89 to what you would like. just make sure you never have a post named "n:" that you want to comment on.
and last but not least, since i wasn't able to get mt-email to rebuild when i posted via email i had to use mt-rebuild to rebuild my site every x hours or minutes or whatever. here's the mt support forum thread for mt-rebuild. it has lots of great info on how to set up a cron job to do that for ya.
i hope this helps. you're welcome to email me with questions however as i said..i tinkered and i played, i suggest you do the same.
update 6.16.03: i just got an email from david raynes, creator of mt-email. apparently he forgot the rebuild code in v 0.2 for new entries. he's gonna work on that. thanks david.