Skip to content

map7/the_merger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TheMerger

A mail merge gem which allows you to do the following;

  • link to a table eg: clients.
  • dynamically collects fields from the linked table and displays them in a helper drop down box
  • creates a letters table to store you custom letters to be mail merged
  • does the mail merging part which is to regex a body of text and replace with fields
  • manages bulk emails
  • manages scheduled emails (optional)

Demo app

There is a demo app here: https://github.com/map7/mailout

Installation

Add this line to your application’s Gemfile:

gem 'the_merger'

And then execute:

bundle

Or install it yourself as:

gem install the_merger

Configure

When using TheMerger in a controller you have to add the following line to the top. EG: the default would be the users controller as you are doing the mail merge there.

include TheMerger

Create a yaml file in your config directory called ‘the_merger.yml’ with something like this

---
merge_model: "Client"

To use the javascript included in this gem put the following in your application.js

//= require the_merger/application

Where you need to insert fields (I usually create a ‘letters’ table) put the following in the form, just above the text_area.

<%= field_selection %>

Give the text_area you want to interact with the class ‘mail_merge_body’ so that the insert button knows where to insert the field selected.

Usage

Currently it’s just one method and this is how you pass it information

Email all

To send a mail merge to all elements within your ‘merge_model’. EG: all clients

TheMerger.mail_merge(
  from: "from@example.com",
  subject: "update_listing",
  body: "Dear [firstname] [lastname], Please update your listing, from Mick")

Email subset

To send a mail merge to all elements within your ‘merge_model’. EG: all clients

TheMerger.mail_merge(
  from: "from@example.com",
  subject: "update_listing",
  body: "Dear [firstname] [lastname], Please update your listing, from Mick")
  group: Client.where(suburb: "Fitzroy")

Email single

To send a mail merge to all elements within your ‘merge_model’. EG: all clients

TheMerger.mail_merge(
  from: "from@example.com",
  subject: "update_listing",
  body: "Dear [firstname] [lastname], Please update your listing, from Mick")
  single: Client.find(params[:id])

Emails can be written using markdown

Markdown reference: http://daringfireball.net/projects/markdown/

This will create a HTML email.

Contributing

  1. Fork it
  2. Create your feature branch (`git checkout -b my-new-feature`)
  3. Commit your changes (`git commit -am ‘Add some feature’`)
  4. Push to the branch (`git push origin my-new-feature`)
  5. Create new Pull Request

Tasks

  • [X] Get all users from the users table
  • [X] Mail merge and output to the screen
  • [X] Make the table a variable
  • [X] Create a method to get all fields from the selected table.
  • [X] Create a helper method to have a dropdown of fields
  • [X] Turn this into an engine so that I can include asset pipeline javascript.
  • [X] Get the Email all button to work
  • [X] Write tests
  • [X] Allow filtering or passing a subset of users to send email to.
  • [ ] Schedule repetitive mail outs
  • [ ] Make compatible with tinymce