Why Mail Engine
- Don't need to export and import your system data to any other mail systems(like mailchimp, mad_mimi).
- Allow user to edit all email templates directly in system admin, save the time of developer to participate in.
- Allow user to add mail sending schedule directly in system admin, don't need developer to add them into code or deploy crontab at server each time when client have new request.
- Fully take advantage of the convenience of loading any system data to mail template. In the past, like using mailchimp, you have to store everything into user list, then you are able to load that into mail template, it increased the complexity of maintaining information in another system.
- If you want to trace your mail, like open rate, click rate and unsubscribe rate, we provide Sendgrid integration configuration to take advantage that system. (More information at http://sendgrid.com)
- Allow logging all sent mails, you can check which mail been sent to which user.
- You can know send the email to the active users, so that you don't need to waste your credits of sendgrid or amazon.
Problem when using third party mail system
We are using mailchimp mostly for the newsletter solution, but it's has many problems that we have to make a new mail engine to fit our needs in real project:
- It is only one newsletter or marketing mail solution, so for system mail, it can do nothing, so for system mail we still go the original way (put them in the rails project.)
- Mailchimp don't support other encode for mail, when sending japanese or chinese mail it will be failed.
- It doesn't support localization, so different language is different campaign, you need to set a lot config for each of them.
- Manage user list is awkward, it even can't create list by API, so you have to create list one by one by hand.
- It can't load other user personal or customized data from system into mail, like latest unchecked news or messages, it's very limited to load info from user list record.
- It doesn't support reusable partials, which like you hope to put a fixed content of footer or header.
- It doesn't support recurring mail sending.
Installation
Step 1:
gem install mail_engine
Step 2:
Add management page needed javascript lib and css files, migration files and mailengineconfig.yml under config directory.
rails g mail_engine:install
Step 3:
Run migration.
rake db:migrate
Step 4:
Add below line to the crontab list of your sever:
### check mail schedule for every 15 minutes ### */4 * * * * sh -c "cd /path/to/your/system && rake mail_engine:sendmail RAILS_ENV=production"
Usage
For System Mail:
Due to the sender of system mail is ActionMailer, so you just need to set template physical store path (e.g. user_mailer/notify) as the mailer template load path, system will load it from database. (Notice, database template will override your file template.)
Mail Engine use Liquid template engine, so you can read the Liquid Reference at http://www.liquidmarkup.org/
Steps:
- Create a template in mail engine.
For Marketing Mail:
For normal marketing mails are quite simple in logic, so don't need logic code in the mail template. So we provide a mail dispatcher which allows user can send marketing mail only by providing the template and select the data pre-defined in system to the mail template, don't need developer to do anything like adding mailer file.
Steps:
- Create a mail tempate in mail engine.
- Create a sending schedule record. (You can specify the users to receive this mail, total sending count, sending period, when start to deliver the first mail and load which data into this template, You also can set condition for the scheduler, like if no specified data in collection, don't send the mail.)
You also can send mail in your program by using: MailEngine::MailDispatcher.marketing mail template name(:to => "Michael he hlxwell@gmail.com", :values => => "Michael He").deliver
Screenshots
Dashboard
Shows the latest report.
Template Management
You can manage the template used in your system, including:
- System mail, has it's own action mailer file.
- Marketing mail, simple logic and without it's own action mailer.
- Partials, you can reused it in any other templates.
Template editing Page
You can see here are many details you can change:
- Template Path, system action mailer can find it when lookup mail template.
- Locale
- Format
- Layout
- Files will used in the template.
- Zip File when you used at creating this template.
- Preview template in time.
Upload html template with image in a zip file
You can create a template by uplaoding a zip file including one html and other images or css files.
Partial and Layout selection
Mail Schedule
You can set a mail sending schedule, here are some useful setting items:
- Marketing Mail Template.
- User Group will be received this mail.
- Total send count.
- Already send count.
- Sending Period.
- Payloads which load from user model and send to template when sending.
- First send date time, this date will indicate when this mail will be send first time, and according to the seding period it will resend at the same time after one period.
- You can set requirements, which been predefined in the system, let the mail not been sent if the requirements is unreached.
Mail Logs
It will log all mails' content been sent, you can turn it off in config file.
Report
Shows detail chart and data list of mail sending stats.