Extending Blog to accept email post

I’m thinking of extending the blog example to allow posting via email. I’m wondering how that fits under the MVC concept? I would like to read the email, check that it is coming from a predefined email address, then using the web model/controllers to post the message.

I’m guessing I’ll need a new model for the email message, which would call a library to read the next new message, but I’m not sure how I will go about calling the controller to post the message.

Any help would be appreciated.

The biggest hurdle to do this, is that you need some sort of integration into your MTA (e.g. sendmail, postfix, …). Think about it: You don’t want to react on a HTTP request, but an email coming in via SMTP. So you need to define some rules, that will e.g. call a script for emails coming in for a specific recipient. That script could be a yiic command that will parse your email and create the apropriate db entries.

For me, the email part is the easy part - I can either have a cron job that periodically checks IMAP, or I can have a script run whenever a new email is delivered.

The problem I have is I’m not too familiar with the MVC model so I’m not sure where to put the code for reading email, how to call the current Post controllers…

Or would I bypass the Post controller, and maybe create an Email controller, that will manipulate the models directly?

You will not use any controller at all, as you are not in a MVC environment here: You don’t need a view to be rendered (or where do you want to display it to the email sender? ;) ). So simply create a console command. You can e.g. use ActiveRecords there like you would in a controller action.

Thanks Mike - I’ll try and create a console command then.