我已經創建了一個解決方案,包裝當前的廣告系列。它的工作原理是這樣的:
- 在mailjet
- 建立廣告活動,該廣告活動創建一個模板
- 返回活動清單中,檢查開始,得到這個廣告系列的ID。進口
- 新方案將在
app/views/shared/_auto_my_new_email_template.html.erb
- 保存爲ERB您可以用新的模板發送電子郵件致電:
- 在mailjet.rake
- 運行rake mailjet添加
510969 => 'my_new_email_template'
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 /任務/ mailjet。耙:
# 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
應用程序/郵寄/ custom_mailer.rb:
class CustomMailer < ActionMailer::Base
default :from => "\"Support\" <[email protected]>"
default :to => "\"Support\" <[email protected]>"
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。這已經生產了幾個月,而且非常有用。
最後一個註釋:@madflo,如果您可以讓我們看到所有在mailjet界面發送的郵件,那就太棒了。 (現在,你可以看到最近發送的50封電子郵件)。我希望能夠檢查一些電子郵件是否至少在一個月前被髮送。
我對這個功能也很感興趣。它現在可用嗎? – htaidirt