Sha256: 102dc1da8f9e4ee01a21c76ae312f9387f0ac74d99fe32c1d15b2ef70f958848

Contents?: true

Size: 1.88 KB

Versions: 12

Compression:

Stored size: 1.88 KB

Contents

class IshManager::OfficeMailer < IshManager::ApplicationMailer

  ## 2023-04-02 _vp_ Continue.
  def send_context_email ctx_id
    @ctx  = Ctx.find ctx_id
    @lead = Lead.find @ctx.lead_id

    @utm_tracking_str = {
      'cid'          => @ctx.lead_id,
      'utm_campaign' => @ctx.tmpl.slug,
      'utm_medium'   => 'email',
      'utm_source'   => @ctx.tmpl.slug,
    }.map { |k, v| "#{k}=#{v}" }.join("&")

    @domain         = Rails.application.config.action_mailer.default_url_options[:host]
    @origin         = "https://#{Rails.application.config.action_mailer.default_url_options[:host]}"

    @unsubscribe_url = Ishapi::Engine.routes.url_helpers.email_unsubscribes_url({
      host: 'text-host-3',
      template_id: @ctx.tmpl.id,
      lead_id:     @lead.id,
      token:       @lead.unsubscribe_token,
    })
    # renderer = Tmp6Ctl.new
    # renderer = IshManager::ApplicationController.new
    # renderer.send( :include, ::IshManager::ApplicationHelper )
    # renderer.send( :request, { host: 'test-host' } )
    renderer = IshManager::ApplicationMailer.new


    renderer.instance_variable_set( :@ctx,              @ctx )
    renderer.instance_variable_set( :@lead,             @ctx.lead )
    renderer.instance_variable_set( :@utm_tracking_str, @utm_tracking_str )
    renderer.instance_variable_set( :@unsubscribe_url,  @unsubscribe_url )

    eval( @ctx.tmpl.config_exe )

    if 'plain' == @ctx.tmpl.layout
      rendered_str = ERB.new( @ctx.body ).result( @ctx.get_binding )
    else
      rendered_str = renderer.render_to_string("ish_manager/email_templates/_#{@ctx.tmpl.layout}")
    end
    @ctx.update({
      rendered_str: rendered_str,
      sent_at: Time.now.to_s,
    })

    mail( from:    @ctx.from_email,
          to:      @ctx.to_email,
          subject: ERB.new( @ctx.subject ).result( @ctx.get_binding ),
          body:    rendered_str,
          content_type: "text/html" )
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ish_manager-0.1.8.482 app/mailers/ish_manager/office_mailer.rb
ish_manager-0.1.8.481 app/mailers/ish_manager/office_mailer.rb
ish_manager-0.1.8.480 app/mailers/ish_manager/office_mailer.rb
ish_manager-0.1.8.479 app/mailers/ish_manager/office_mailer.rb
ish_manager-0.1.8.478 app/mailers/ish_manager/office_mailer.rb
ish_manager-0.1.8.477 app/mailers/ish_manager/office_mailer.rb
ish_manager-0.1.8.476 app/mailers/ish_manager/office_mailer.rb
ish_manager-0.1.8.475 app/mailers/ish_manager/office_mailer.rb
ish_manager-0.1.8.474 app/mailers/ish_manager/office_mailer.rb
ish_manager-0.1.8.473 app/mailers/ish_manager/office_mailer.rb
ish_manager-0.1.8.472 app/mailers/ish_manager/office_mailer.rb
ish_manager-0.1.8.471 app/mailers/ish_manager/office_mailer.rb