Class: IshManager::OfficeMailer

Inherits:
ApplicationMailer show all
Defined in:
app/mailers/ish_manager/office_mailer.rb

Instance Method Summary collapse

Methods inherited from ApplicationMailer

#option_alert, #shared_galleries, #stock_alert

Instance Method Details

#send_campaign_email(campaign_id, c_lead_id) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/mailers/ish_manager/office_mailer.rb', line 4

def send_campaign_email campaign_id, c_lead_id
  @ctx = @campaign = ::Ish::EmailContext.find campaign_id
  @lead = EmailCampaignLead.find c_lead_id

  if @lead.sent_at
    raise "This campaign_lead #{@lead.id} has already been sent."
  end

  actl = ActionController::Base.new
  actl.instance_variable_set( :@ctx, @ctx )

  @pixel_tracking = {
    'v'   => 1,
    'tid' => 'UA-53077236-2',
    'cid' => @lead.cid,
    't'   => 'event',
    'ec'  => 'email',
    'ea'  => 'open',
    'utm_source'   => @campaign.slug,
    'utm_medium'   => 'email',
    'utm_campaign' => @campaign.slug,
  }.map { |k, v| "#{k}=#{v}" }.join("&")
  actl.instance_variable_set( :@pixel_tracking, @pixel_tracking )

  @click_tracking = {
    'cid' => @lead.cid,
    't'   => 'event',
    'ec'  => 'email',
    'ea'  => 'clk-ctct', # clicked contact us
    'utm_source'   => 'eror1',
    'utm_medium'   => 'email',
    'utm_campaign' => 'eror1',
  }.map { |k, v| "#{k}=#{v}" }.join("&")
  actl.instance_variable_set( :@click_tracking, @click_tracking )

  actl.instance_variable_set( :@lead, @lead )

  template = "render/_#{@ctx.email_template.slug}"
  rendered_str = actl.render_to_string("ish_manager/email_templates/_#{@ctx.email_template.slug}")
  @lead.update( rendered_str: rendered_str, sent_at: Time.now )

  mail( from: @ctx.from_email,
    to: @lead.email,
    bcc: '[email protected]', # @TODO: change _vp_ 2022-11-21
    subject: @ctx.subject,
    template_name: template )
end

#send_context_email(ctx_id) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/mailers/ish_manager/office_mailer.rb', line 52

def send_context_email ctx_id
  @email_ctx = ::Ish::EmailContext.find ctx_id
  ac = ActionController::Base.new
  ac.instance_variable_set( :@email_ctx, @email_ctx )

  case @email_ctx.email_template.type
  when 'partial'
    template = "render/_#{@email_ctx.email_template.slug}"
    rendered_str = ac.render_to_string("ish_manager/email_templates/_#{@email_ctx.email_template.slug}")
  when 'plain'
    @body = @email_ctx.body_templated
    template = "render/plain"
    rendered_str = ac.render_to_string("ish_manager/email_templates/plain")
  end

  @email_ctx.update( rendered_str: rendered_str, sent_at: Time.now )

  mail( from: @email_ctx.from_email,
        to: @email_ctx.to_email,
        bcc: '[email protected]',
        subject: @email_ctx.subject,
        template_name: template )
end