Email posts
The steps below are also useful to automate a mailbox on Exchange.
Just read through it and pick out the pieces that make it work.
Wordpress has always had a function that allows you to send an email to ‘a’ address and it will pick it up there and put it on your blog.
Unfortunatley it is not very stable and very feature less, so I’m running a plugin called Postie which is nothing but feature less. You can read about and download Postie at economysizegeek.com
Getting the mail
If you’re running your wordpress blog on a linux machine then you would use cron to load the getmail page every once so often, like every 5 minutes or once an hour, but if you’re on Windows (I am) then that’s not an option. In Windows you’d rely on the scheduler service to run this job, but it really doesn’t work well if you need to run it less then once a day.
So, as I’m also running Exchange I looked into how to do this and found two solutions. Event sinks, which is the proper way on E2k3, and the Eventhandler, which came from E5.5 i believe.
Event sinks are very good if you need to capture all emails coming in through the SMTP connector, but it’s just a hazzle and very complicated to get it to only work on one mailbox.
The Eventhandler though still has several steps you need to perfom to set it up, but when it’s up running then you control what should happen through Outlook.
That fits for me!
The theory
The theory behind this is simple:
- A email arrives in the exchange mailbox foo@jarnaker.com
- This triggers a script as an item has been created
- The script runs ‘php get_mail.php’ which comes with postie
- When the page (get_mail.php) loads then the emails are imported
It works like a charm and only seconds after the email has arrived the post is on my blog.
Setting it up
For this scenario to work, as I use it, you will need:
- A W2kx server with IIS/Apache and PHP
- Wordpress working and running
- Postie installed and working
- A Exchange server with file access to the get_mail.php file (I run everything off once box)
In AD create two users, one called eventhandler and one called postie. User eventhandler should be part of the domain admins group and user postie should have a mailbox associated with him.
In user posties profile configure Exchange advanced - Mailbox rights and give the user eventhandler full mailbox rights.
Open services.msc and configure the service Microsoft Exchange Event to log on with the eventhandler user account. Set the service to start automatically and start the service.
In Exchange system manager go to folders and right click on public folders and select view system folders. Expand the events root and select properties of EventConfid_servername.
In permissions - client permissions add the user postie with role owner.
Configure outlook for the postie account and open it.
Go to tools - options - other - advanced options - addin manager and make sure that server scripting is checked. If it is not there then you’re running Outlook in non-exchange mode.
Now, right click on the inbox and select properties. You should have a new tab called Agents, if not then restart Outlook.
On the agent tab click edit. Make sure that when a new item is posted in this folder is checked and then click on edit script.
Replace the existing script with this:
<SCRIPT RunAt=Server Language=VBScript>
Option Explicit
' DESCRIPTION: Fired when a new message is added to the folder
Public Sub Folder_OnMessageCreated
Dim objShell, objExecObject
Set objShell = CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("D:\\Progra~1\\php\\php-win.exe d:\\INetPub\\wwwroot\\www.jarnaker.com\\wp-content\\plugins\\postie\\get_mail.php")
script.response = "Executed."
End Sub
</SCRIPT>
You’ll need to change the 8th line to reflect the paths to your php-win.exe as well as to the get_mail.php file.
Now save and close the script and exit out of the windows and send yourself a email. If everything is good then your email should appear in your inbox just to disappear a couple of seconds later. If the mail doesn’t disappear then the script doesn’t run properly and you might want to have a look in the application eventlog as well as the log at inbox - properties - agents - edit - logs.
If the script fired off then you should have a timestamp there and Executed.
