Class: MailSpy::CoreMailer

Inherits:
ActionMailer::Base
  • Object
show all
Defined in:
app/mailers/mail_spy/core_mailer.rb

Instance Method Summary collapse

Instance Method Details

#template(email) ⇒ Object



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
# File 'app/mailers/mail_spy/core_mailer.rb', line 5

def template(email)
  # Slight hack to provide information to helpers
  @_email = email
  @template_values = email.template_values
  esp = MailSpy.esps[email.email_service_provider]
  email_hash = {}

  # Evaluate the subject line as erb
  if email.subject.present?
    subject = ERB.new(email.subject).result(binding)
    email_hash[:subject] = subject
  end

  # Set Headers
  std_email_keys = [:to, :cc, :bcc, :from, :message_id, :sender, :reply_to]
  std_email_keys.each { |key| set_if_present(email_hash, email, key) }
  email.headers.each {|key, value| headers[key] = value} if email.headers.present?

  # Create the mail message
  mail_message = mail(email_hash) do |format|
    format.text { render :inline => email.text_erb }
    format.html { render :inline => email.html_erb }
  end

  mail_message.delivery_method.settings.merge!(
    {
      :address => esp.address,
      :user_name => esp.user_name,
      :password => esp.password,
      :port => esp.port,
      :authentication => esp.authentication,
      :enable_starttls_auto => esp.enable_starttls_auto,
      :domain => esp.domain
    })

  mail_message
end