User Manual

Mailers

Mailers allow you to send email notifications on a Create or Update action in the API.

You can create any amount of Mailers through the Interface admin, specifying the following:

  • Name (the name you use to refer to the Mailer elsewhere in Interface)
  • Subject
  • Email From
  • Email To (can be multiple addresses, separated by commas)
  • Email body
  • Template name

Example

If you wanted to allow users to post a comment, and also email an administrator so they can keep tabs on any inappropriate comments, you could set up a Mailer to send an email to the administrator. You would set the fields in the following way:

  • Name: New Comment Mailer
  • Subject: New Comment Posted
  • Email From: no-reply@example.com
  • Email To: administrator@example.com
  • Email Body: A comment has been posted, here is the information:
  • Template name: new_comment

Tell your form to use the Mailer

You can tell Interface to send out an email upon creating or updating an item in the API by adding a hidden form field in the form used to create the item. In the example of a new Comment, you would add the following into your new Comment form:

<input type="hidden" name="email[comment]" value="New Comment Mailer" />

This will tell Interface that upon successful creation of the Comment, send an email out using this Mailer.

Create the Mailer template

The last step is to create a new template under templates/content_mailer called new_comment.html.erb.

The Mailer template has access to the content item you are creating or updating through the @info[:content] variable. So in the case of the above Comment, you could display the contents of the comment in the template, like so:

Name: <%= @info[:content].name %>
Email: <%= @info[:content].email %>
Body: <%= @info[:content].body %>

This is then rendered and appended to the email body after the Body content specified in the Mailer (allowing some boilerplate copy outside of the template, if needed).

Sending to different recipients from the same Mailer.

Usually when using a Mailer, you specify the recipients in that Mailer’s “to” field. However, sometimes you would rather send an email from the same Mailer to different recipients based on various conditions. Interface does not accept recipients directly from the API (basically to prevent malicious scripts from using Interface as a spam farm), but there is a way to specify recipient emails that reside in content within Interface. The way this works is to specify the Model for the content containing the email addresses, which particular content items to use as sources of the addresses, and what property these addresses reside in. The entire system takes the following parameters:

email[identifier]=mailer_name (the identifier is unique and used to provide the ability to trigger several mailers at once).
to_model[identifier]=ModelContainingAddresses
to_group[identifier]=1,5,55  (a list of id's of the content objects containing the addresses)
to_prop[identifier]=email_address_property (whatever that happens to be)

Interface will fetch the pieces of content of type “to_model” given by the ids in the “to_group” field and extract the value specified by “to_prop”. As long as those values are populated by valid email addresses, the emails will be sent to those recipients.