We had the same issue, so I wrote simple rake task for our ROR app, which removes |MC_PREVIEW_TEXT| section from Mandrill templates automatically. Here an example of my rake task:
require 'mandrill'
namespace :mandrill do
desc 'Removes *|MC_PREVIEW_TEXT|* section for all email templates in mandrill app'
task remove_mc_preview_text: :environment do
# Templates with handlebars merge language
templates = [
'template-example-1',
'template-example-2',
]
mandrill = Mandrill::API.new 'YOUR_API_KEY'
templates.each do |name|
begin
puts "Processing the template: #{name}"
# Get the information for an existing template
result = mandrill.templates.info name
# Finds the section with MC_PREVIEW_TEXT inside a template and substitutes it to the empty string
code = result['code'].sub(/\<\!\-\-\*\|IF:MC_PREVIEW_TEXT[[:ascii:]]+END:IF\|\*\-\-\>/m, '')
# If nil is provided for any fields, the values will remain unchanged.
from_email = nil
from_name = nil
subject = nil
text = nil
labels = nil
# Set to false to update the draft version of the template without publishing
publish = true
# Update the code for an existing template
mandrill.templates.update name, from_email, from_name, subject, code, text, publish, labels
puts "Successfully deleted *|MC_PREVIEW_TEXT|* section from the template: #{name}"
rescue Mandrill::Error => e
# Mandrill errors are thrown as exceptions
puts "A mandrill error occurred: #{e.class} - #{e.message}"
end
end
puts 'Done!'
end
end
There are few steps should be done to make it work:
- Install the Mandrill API client as a gem:
gem install mandrill-api
or add to your Gemfile: gem 'mandrill-api'
- Create any rake task (for example remove_mc_preview_text.rake) with the code listed above inside the lib/tasks/ folder
- Change 'YOUR_API_KEY' to your real Mandrill API Key
- Change template names in
templates
array to your real templates, if for some reason you don't know them, you can find them here https://mandrillapp.com/templates
And finally run this command in the root folder of your rails app:
bundle exec rake mandrill:remove_mc_preview_text
If you use any other programming language you can write similar script using my as an example, see Mandrill API Clients for different programming languages.