Jun 8, 2021

Simple ticketing system using ExpressionEngine Moblog

A long-established feature of ExpressionEngine is the Moblog, or mobile weblog, which has been part of the installation since version 1.6. Simply put, a moblog allows one to email content to a specific address, which will automatically import into a blog.

I originally used the moblog when I was in Lithuania adopting our son Darius. This was in 2007, and in that part of Europe widespread internet wasn't common outside of a hotel or an internet cafe. So while my wife and I were going through the adoption process, doing some sightseeing here and there, we would blog to our family and friends via the moblog, writing ourselves emails on our antiquated smartphones.

The emails would stay in the outbox our phone, and when we were back to an internet connection, the messages would send to a predefined email inbox (e.g. myblog@oursite.com).

Moblog: the unsung hero

We had a private ExpressionEngine blog for our adoption journey which, employing the moblog, would parse the message content and import into channel entries defaulting to "Draft" status. We would then log into the website backend to review the messages of the day and make final tweaks before publishing.

In this niche use case it was perfect. I always thought more useful applications would emerge, particuarly for our website customers, but this hadn't been the case until recently.

Why use it?

At Creative Arc, we have used Basecamp as a project management system for a very long time, long enough where we're not really keen to switch even though there are compelling alternatives. 

E-mail communication is a huge part of serving clients for any agency. Most of our customers respond to our project messages by logging in to Basecamp, or by replying to Basecamp threads directly in their e-mail client. A sizable portion of our contacts don't (or won't) use Basecamp for a variety of reasons, instead writing us direct e-mails. 

Unfortunately, when emails are filling our inboxes, they might not get the prompt attention they deserve because our entire team does not have visiblity. So, I'm often faced with posting or pasting a customer's email back into Basecamp so we have access to it as a team. As a one-off, it's not that much work. But when it's a dozen occurences every day, it gets unwieldy pretty quickly.

Moblog to the rescue

This continual struggle of coralling client emails led me to consider the Moblog again. If ExpressionEngine could collect the e-mail content, we would be able to get that content to the proper projects in Basecamp. The basic steps are as follows: 

  1. Install the first-party Moblog module
  2. Create an e-mail account to collect submissions
  3. Create a channel to store Moblog entries
  4. Configure the Moblog
  5. Test E-mail collection
  6. Configure Moblog cron
  7. Configure EE template display
  8. Integrate the Basecamp API

Let's get started! (the following image examples are current as of ExpressionEngine 6.0.3, June 2021)

1) Install the first-party Moblog module

2) Create an e-mail account to collect submissions

This is self-explanatory, but you should absolutely limit allowed senders. So in our case, we limit submissions to emails originating from our company in the moblog settings ("Valid 'From' Emails for Moblog"). More on that later.

3) Create a channel to store Moblog entries

You shouldn't need many fields; the Title of the entry will default to the email subject. A body field should suffice, unless you want file fields for email attachments.

4) Create and configure the Moblog

Navigate to the Moblog addon in the ExpressionEngine backend. The settings are self-explanatory to any seasoned EE developer. Below is an example of what we use. The Moblog documentation can point you to the specifics.

The configuration gives you several useful options. You have to define the email address and server credentials for ExpressionEngine to be able to retrieve the messages. You can decide if you want to handle file attachments and also whether or not entries stay in draft mode or go directly to publish.

In our case, we used Gmail which was nice because it allowed me to restrict receiving messages from only particular accounts. This allows us to limit Moblog entries being created by our own company domain.

5) Test E-mail connection

Let's see if our configuration worked. Write a basic email with a minimal Subject and Body, addressed to your Moblog email address (myblog@mydomain.com).

Navigate to the Moblog module in the EE backend and click "check now."

Ideally, the Moblog will report that no new emails could be found, or that it had success retrieving:

Navigate to your Moblog channel, and you'll see the content that was just imported from your email.

6) Configure Moblog cron

The Moblog needs a URL that we can use with a cron job using curl or wget.

Create a template, such is mydomain.com/my_moblog/check. A one-liner wins the day!

{exp:moblog:check silent="no" which="emails_to_tasks"}

Then, a simple crontab (I chose 5 minute interval) to hit the URL and trigger the Moblock check-email process.

*/5 * * * * curl -s 'https://mydomain.com/my_moblog/check' > /dev/null;

If you simply need a basic Moblog, you're done! For an example of taking it further, please read on.

7) Taking it further: Configure the ExpressionEngine templates

Remember, our goal is to corral one-off emails from customers and get them back into Basecamp. The Moblog succeeded in retrieving the emails and saving them as channel entries. Next, we need to get the content to Basecamp.

The code snippet below is a fairly basic Channel Form. The form loops through the entries that have been imported into our Moblog channel, and our EE templates present a basic interface we'll use to tell Basecamp what to do with the content: namely, are we posting a new thread? A ToDo? And who are the asignees and recipients?


The rendered HTML looks something like this:

Key functions of this Channel Form: we can select a project, such as ACME Construction, then choose to post the message content to a particular ToDo list, and/or create a Basecamp thread, while assigning individuals as recipients or todo assignees. Upon submitting the form, the channel entries are fed to another template that is easy for the Basecamp API to process, which we detail below.

8) Integrate the Basecamp API

In this example, the only piece created outside of ExpressionEngine was a little bit of middleware in the way of a shell script. This could be PHP, an ExpressionEngine addon, however you want to handle it. The Basecamp API is too much to cover here, but the process of using the Moblog to get email content into an EE channel proved to be the biggest step.

I won't get into the specifics of the shell script because it's fairly convoluted, but it is limited to a few fairly basic Basecamp API calls. 

In this curl statement, note the EE template tags of title, {person_id}, entry_date, and {task_project}. The shell script is simply looping through the output from the Moblog channel, running the necessary curl command in each case.


We have found this to be an immensely useful tool, because we can use the systems we are familiar with (namely Basecamp) without having to abandon them for a new system that might do more than we need. ExpressionEngine and the Moblog provided a great way of filling this tiny void that keeps client communication in front of our team where it needs to be.

Want to share this post?