Class: Mailer

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationMailer

#null_mail

Class Method Details

.format_exception(options) ⇒ Object



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
# File 'app/mailers/mailer.rb', line 12

def self.format_exception(options)
  request_context = +''
  if options[:message]
    request_context << options[:message]
    request_context << "\n-----------------------------------------------\n"
  end
  if options[:current_user]
    request_context << "Current User: #{options[:current_user]}"
    request_context << "\n-----------------------------------------------\n"
  end

  if options[:current_account]
    request_context << "Current Account: #{options[:current_account]}"
    request_context << "\n-----------------------------------------------\n"
  end

  if options[:exception]
    request_context << "Exception: #{options[:exception].to_s}\n\n"
    request_context << "Backtrace:"
    request_context << options[:exception].backtrace.join("\n")
    request_context << "\n-----------------------------------------------\n"
  end

  if options[:request]
    request_context << "\n\nRequest:"
    options[:request].env.each{|k,v| request_context << "#{k} : #{v}\n" }
    request_context << "\n-----------------------------------------------\n"
  end


  return request_context
end

Instance Method Details

#admin_notification(subj, message = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/mailers/mailer.rb', line 45

def admin_notification(subj, message=nil)
  if message.nil?
    message = subj
    subj = "An admin notification was sent"
  end
  if message.is_a?Hash
    @message = Mailer.format_exception(message)
  else
    @message = message
  end
  mail(:to => ADMINISTRATOR_EMAIL, :subject => subj, :from => ADMINISTRATOR_EMAIL)
end

#canada_post_manual_void_email(delivery, tracking_numbers) ⇒ Object



108
109
110
111
112
113
114
# File 'app/mailers/mailer.rb', line 108

def canada_post_manual_void_email(delivery, tracking_numbers)
  store_id = ((delivery.customer.store.id) rescue 1)
  sender = 'heatwaveteam@warmlyyours.com'
  @delivery = delivery
  @tracking_numbers = tracking_numbers
  mail(from: sender, to: 'orders@warmlyyours.com', subject: "Delivery was voided in Heatwave but shipments were not cancelled through Canada Post API, see enclosed tracking numbers")
end

#canada_post_manual_void_email_for_mail_activity(mail_activity, tracking_numbers) ⇒ Object



100
101
102
103
104
105
106
# File 'app/mailers/mailer.rb', line 100

def canada_post_manual_void_email_for_mail_activity(mail_activity, tracking_numbers)
  store_id = mail_activity.store.id
  sender = 'heatwaveteam@warmlyyours.com'
  @mail_activity = mail_activity
  @tracking_numbers = tracking_numbers
  mail(from: sender, to: 'orders@warmlyyours.com', subject: "Mail Activity was voided in Heatwave but shipments were not cancelled through Canada Post API, see enclosed tracking numbers")
end

#default_url_optionsObject



8
9
10
# File 'app/mailers/mailer.rb', line 8

def default_url_options
  UrlHelper.default_url_options({ host: CRM_HOSTNAME })
end

#generic_mailer(options) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/mailers/mailer.rb', line 58

def generic_mailer(options)
  options[:extra_headers] ||= {}
  sender = options[:from]
  sender_email = sender.try(:email) || sender.to_s || "info@warmlyyours.com"
  files_to_attach = options[:attachments] || []
  document_attachments = []
  files_to_attach.each do |a|
    if a.class == Upload and a.category == "purchase_order"
      options[:cc] = ACCOUNTS_PAYABLE_EMAIL
    end
    if a.class == Upload and (a.category == "organization_quote_pdf" or a.category == "msrp_quote_pdf")
      attachments["Quote #{a.resource.reference_number}.pdf"] = a.attachment.data
    elsif a.class == Upload and a.category == "invoice_pdf"
      attachments["Invoice #{a.resource.reference_number}.pdf"] = a.attachment.data
    elsif a.respond_to?('attachment') and a.attachment.present?
      attachments[a.attachment_name] = a.attachment.data
    elsif a.respond_to?('legacy_attachment') and a.legacy_attachment.file?
      attachments[a.attachment_name] = a.attachment.data
    elsif a.is_a? Item #Publication
      if options[:transmission_method] == "fax" or !a.is_available_to_public
        attachments[a.public_file_name] = a.attachment.data
      elsif a.is_available_to_public
        document_attachments << a
      end
    end
  end

  headers["Reply-to"] = options[:reply_to] || sender_email

  @documents_plain = Communication.documents_plain(document_attachments)
  @documents_html = Communication.documents_html(document_attachments)
  @message_plain = options[:message]
  @message_html = Communication.text_to_html(options[:message])
  @signature_plain = options[:signature]
  @signature_html = Communication.signature_to_html(options[:signature])
  @no_verbage = options[:no_verbage]
  options[:extra_headers].each do |k,v|
    headers[k] = v
  end
  mail(:to => options[:to], :from => sender_email, :cc => options[:cc], :bcc => options[:bcc], :subject => options[:subject])
end

#personal_connect(sender, values = {}) ⇒ Object



140
141
142
143
144
# File 'app/mailers/mailer.rb', line 140

def personal_connect(sender,values={})
  @values = values
  @no_verbage = true
  mail(from: sender, to: "webenquiries@warmlyyours.com", subject: "A personal connect enquiry was made from #{sender} on: #{Time.current}")
end

#purolator_manual_void_email(delivery, tracking_numbers) ⇒ Object



116
117
118
119
120
121
122
# File 'app/mailers/mailer.rb', line 116

def purolator_manual_void_email(delivery, tracking_numbers)
  store_id = ((delivery.customer.store.id) rescue 1)
  sender = 'heatwaveteam@warmlyyours.com'
  @delivery = delivery
  @tracking_numbers = tracking_numbers
  mail(from: sender, to: 'orders@warmlyyours.com', subject: "Delivery was voided in Heatwave but shipments were not cancelled through Purolator API, see enclosed tracking numbers")
end

#saia_schedule_pickup_failed_email(email, deliveries, message) ⇒ Object



124
125
126
127
128
129
130
# File 'app/mailers/mailer.rb', line 124

def saia_schedule_pickup_failed_email(email, deliveries, message)
  sender = 'heatwaveteam@warmlyyours.com'
  @carrier = 'Saia'
  @deliveries = deliveries
  @message = message
  mail(from: sender, to: email, subject: "Could not schedule SAIA pickup, you may want to schedule it manually")
end

#schedule_pickup_failed_email(email, carrier, deliveries, message) ⇒ Object



132
133
134
135
136
137
138
# File 'app/mailers/mailer.rb', line 132

def schedule_pickup_failed_email(email, carrier, deliveries, message)
  sender = 'heatwaveteam@warmlyyours.com'
  @carrier = carrier
  @deliveries = deliveries
  @message = message
  mail(from: sender, to: email, subject: "Could not schedule #{carrier} pickup, you may want to schedule it manually")
end