現在のキャンペーン システムをラップするソリューションを作成しました。それはこのように動作します:
- メールジェットでキャンペーンを作成する
- そのキャンペーンのテンプレートを作成する
- キャンペーン リストに戻り、開始を調べて、このキャンペーンの ID を取得します。
510969 => 'my_new_email_template'
mailjet.rakeに追加
- rake mailjet:import を実行します
- 新しいテンプレートはerbとして保存されます
app/views/shared/_auto_my_new_email_template.html.erb
- 次のように呼び出して、新しいテンプレートを含むメールを送信できます。
CustomMailer.send_mailjet_email('my_new_email_template', emails, subject, {USER_NAME: 'John'})
最後のパラメーターは、電子メールの John に置き換え===USER_NAME===
られます (電子メールに変数を含めることができる手段として)。mailjet では、次のように記述します。
Hello, ===USER_NAME===,
click here to activate your account: ===ACTIVATION_LINK=== ...
lib/tasks/mailjet.rake :
# WARNING: you need to add gem 'mailjet' in Gemfile for development group to use this task
# if mailjet is included in development, this breaks mails_viewer
# (see http://stackoverflow.com/questions/17083110/the-gem-mailjet-breaks-mails-viewer)
namespace :mailjet do
desc "Importe les templates d'emails de mailjet dans l'appli. (inscription, mot de passe perdu etc)"
task :import => :environment do
templates = {
510969 => 'reset_password_instructions',
510681 => 'contact_request'
# more templates here
}
templates.each do |id, path|
fullpath = "app/views/shared/_auto_#{path}.html.erb"
out_file = File.new(fullpath, 'w')
out_file.puts(Mailjet::Campaign.find(id).html)
out_file.close
puts "Importing email ##{id} to #{fullpath}\n"
end
end
end
app/mailers/custom_mailer.rb :
class CustomMailer < ActionMailer::Base
default :from => "\"Support\" <contact@yourdomain.com>"
default :to => "\"Support\" <contact@yourdomain.com>"
def send_email(emails, content, subject, reply_to = nil)
@emails = emails.split(',')
@content = content
@emails.each do |m|
#logger.info "==========> sending email to #{m}"
mail(to: m, subject: subject, reply_to: reply_to) do |format|
format.html { content }
#format.text { content }
end.deliver
end
end
def send_mailjet_email(template, emails, subject, params = {}, reply_to = nil)
template = "app/views/shared/_auto_#{template}.html.erb"
content = File.read(template) # can't render twice with rails
params.each do |key, value|
key = "===#{key.upcase}==="
content.gsub!(key, value)
end
content.gsub!('Voir la version en ligne', '')
content.gsub!(t('mailjet_unsubscribe'), '')
content.gsub!(/Voir[^\w]+la[^\w]+version[^\w]+en[^\w]+ligne/, '')
content.gsub!('https://fr.mailjet.com/campaigns/template/', '') # sometimes mailjet appends this at the begining of links
content = content.html_safe
CustomMailer.send_email(emails, content, subject, reply_to)
end
end
これが整ったら、マネージャーに、好きなようにメールを編集するように伝えることができます。===USER_NAME===
または他の変数を使用できることを彼に伝えます。彼が終わったら、私はただrake mailjet:import
、それはすべてのテンプレートをerbとして取得します. これは数か月前から生産されており、非常に便利です。
最後に 1 つ: @madflo、mailjet インターフェイスで送信済みのすべてのメールを表示できるようにしていただければ、それは素晴らしいことです。(現在、最近送信された 50 件程度のメールを確認できます)。たとえば、少なくとも 1 か月前にメールが送信されたかどうかを確認できるようにしたいと考えています。