Class: Notifun::MessageMailer

Inherits:
Object
  • Object
show all
Includes:
Premailer::HtmlToPlainText
Defined in:
app/mailers/notifun/message_mailer.rb

Instance Method Summary collapse

Instance Method Details

#send_message(email, subject, html, text, message_template, options = {}) ⇒ Object



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
# File 'app/mailers/notifun/message_mailer.rb', line 6

def send_message(email, subject, html, text, message_template, options={})
  @notifun_models = message_template.models

  if options[:attachments].present?
    options[:attachments].each do |key, value|
      attachments[key] = value
    end
  end

  if options[:instance_variables].present?
    options[:instance_variables].each do |key, value|
      instance_variable_set("@#{key}", value)
    end
  end

  settings = {
    to: email,
    subject: subject
  }

  if options[:from].present?
    settings[:from] = options[:from]
  end
  if options[:reply_to].present?
    settings[:reply_to] = options[:reply_to]
  end

  if Rails.version[0].to_i > 4
    hack_layout = _layout(["text"])
  else
    hack_layout = _layout
  end

  if Notifun.configuration.premailer_html_to_text && defined?(Premailer)
    text = text.dup
    text = convert_to_text(text)
  end

  mail(settings) do |format|
    format.text { render plain: text, layout: hack_layout }
    format.html { render html: html.html_safe, layout: hack_layout }
  end
end