Class: CommunicationMailer
- Inherits:
-
ApplicationMailer
- Object
- ActionMailer::Base
- ApplicationMailer
- CommunicationMailer
- Defined in:
- app/mailers/communication_mailer.rb
Constant Summary collapse
- MARKETING_CATEGORIES =
announcements, events, newsletters, promotions, webinars
Campaign::CATEGORIES
Instance Method Summary collapse
-
#email(email_from, email_to, subject, body, email_options = nil) ⇒ Object
template : An email template class merge_options : parameters for liquid options : email options (:to, :from, :cc, :bcc, :headers, :attachments).
Methods inherited from ApplicationMailer
Instance Method Details
#email(email_from, email_to, subject, body, email_options = nil) ⇒ Object
template : An email template class
merge_options : parameters for liquid
options : email options (:to, :from, :cc, :bcc, :headers, :attachments)
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 51 52 53 54 55 56 57 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 |
# File 'app/mailers/communication_mailer.rb', line 13 def email(email_from, email_to, subject, body, = nil) ||= {} is_marketing_email = [:category] && MARKETING_CATEGORIES.include?([:category]) ([:headers] || {}).each do |k, v| headers[k] = v end ([:uploads] || []).each do |u| [u. || "attachment_#{u.id}"] = u..data end if [:appointment].present? ["#{[:appointment].events.first.summary.parameterize.underscore}.ics"] = { mime_type: 'application/ics', content: [:appointment].to_ical } end # Generate a unique message id based on the sender credential server hostname # We try here to match the authenticated sender SPF record or at least not to use # the rails generic which is the server name, e.g heatwave-app or heatwave-util, # supposedly this help with spam scoring server_fqdns = if is_marketing_email Heatwave::Configuration.fetch(:smtp_credentials, :warmlyyours_marketing, :fqdns) else Heatwave::Configuration.fetch(:smtp_credentials, :warmlyyours_transaction, :fqdns) end server_fqdns ||= 'warmlyyours.com' headers['Message-ID'] = "<#{SecureRandom.uuid}@#{server_fqdns}>" template_name = [:template] || 'email' = { from: email_from, to: email_to, subject: subject, template_path: 'communication_mailer', template_name: template_name } [:cc] = [:cc] [:bcc] = [:bcc] [:reply_to] = [:reply_to] if [:reply_to].present? [:skip_premailer] = true if [:skip_premailer].to_b [:references] = [:references] if [:stylesheet].present? @external_stylesheet = "emails/#{[:stylesheet]}" end @subject = subject @body = body @inline_stylesheet = [:inline_css] @show_mailing_address = [:show_mailing_address] = [] if (@list_unsubscribe_link = [:list_unsubscribe_link]) << "<#{@list_unsubscribe_link}>" end if (@list_unsubscribe_email = [:list_unsubscribe_email]) << "<mailto:#{@list_unsubscribe_email}>" end @fax_unsubscribe_link = [:fax_unsubscribe_link] if .present? ['List-Unsubscribe'] = .join(",") end if Rails.env.production? && is_marketing_email [:delivery_method_options] = { user_name: Heatwave::Configuration.fetch(:smtp_credentials, :warmlyyours_marketing, :user_name), password: Heatwave::Configuration.fetch(:smtp_credentials, :warmlyyours_marketing, :password) } end x_smtpapi = SendgridSmtpApi.build_x_smtpapi_header( unique_args: [:unique_id].present? ? { unique_id: [:unique_id] } : nil ) Rails.logger.debug { "[CommunicationMailer] X-SMTPAPI: #{x_smtpapi}" } if Rails.env.development? headers['X-SMTPAPI'] = x_smtpapi mail() end |