jam-cloud/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb

41 lines
1004 B
Ruby
Raw Permalink Normal View History

module JamRuby
class BatchMailer < ActionMailer::Base
include SendGrid
layout "user_mailer"
sendgrid_category :use_subject_lines
sendgrid_unique_args :env => Environment.mode
2014-03-19 16:32:53 +00:00
def _send_batch(batch, users)
@batch_body = batch.body
2014-03-19 16:32:53 +00:00
emails = users.map(&:email)
sendgrid_recipients(emails)
sendgrid_substitute(EmailBatch::VAR_FIRST_NAME, users.map(&:first_name))
sendgrid_substitute('@USERID', users.map(&:id))
2014-03-19 16:32:53 +00:00
batch.did_send(emails)
2014-03-18 22:50:06 +00:00
2014-05-06 06:41:10 +00:00
mail(:to => emails,
2014-03-18 22:50:06 +00:00
:from => batch.from_email,
:subject => batch.subject) do |format|
format.text
format.html
end
end
def send_batch_email(batch_id, user_id)
user = User.find_by_id(user_id)
2014-04-05 21:25:47 +00:00
batch = EmailBatch.find(batch_id)
self._send_batch(batch, [user])
2014-03-19 16:32:53 +00:00
end
2014-03-18 22:50:06 +00:00
2014-03-19 16:32:53 +00:00
def send_batch_email_test(batch_id)
2014-04-05 21:25:47 +00:00
batch = EmailBatch.find(batch_id)
2014-03-19 16:32:53 +00:00
users = batch.test_users
self._send_batch(batch, users)
end
end
end