Class: CommunicationMailer
- Inherits:
-
ApplicationMailer
- Object
- ActionMailer::Base
- ApplicationMailer
- CommunicationMailer
- Defined in:
- app/mailers/communication_mailer.rb
Overview
ActionMailer: communication.
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) rubocop:disable Metrics/AbcSize -- pre-existing god-method (95+ on master); out of scope to decompose here.
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)
rubocop:disable Metrics/AbcSize -- pre-existing god-method (95+ on master); out of scope to decompose here
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/mailers/communication_mailer.rb', line 15 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 # Open/click tracking consent (CNIL/Garante). Communication#deliver decides # this per-recipient from the address itself and sets :disable_email_tracking; # when set, disable the SendGrid opentrack/clicktrack filters via X-SMTPAPI. disabled_filters = [:disable_email_tracking] ? %i[opentrack clicktrack] : [] ([:uploads] || []).each do |u| if u.try(:category) == 'paperless_qr_png' # Embed the USPS Label Broker QR inline (CID) so the RMA email body can # show it via <img src="cid:rma-qr-<id>"> (see Rma#paperless_return_html) # rather than as a separate attachment. Explicit content_id so the cid in # the pre-rendered body matches deterministically (Gmail/Outlook safe). file_name = "rma-qr-#{u.id}.png" .inline[file_name] = u..data [file_name].content_id = "<rma-qr-#{u.id}>" else [u. || "attachment_#{u.id}"] = u..data end end ["#{[:appointment].events.first.summary.parameterize.underscore}.ics"] = { mime_type: 'application/ics', content: [:appointment].to_ical } if [:appointment].present? # 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] @external_stylesheet = "emails/#{[:stylesheet]}" if [:stylesheet].present? @subject = subject @body = body @inline_stylesheet = [:inline_css] @show_mailing_address = [:show_mailing_address] = [] << "<#{@list_unsubscribe_link}>" if (@list_unsubscribe_link = [:list_unsubscribe_link]) << "<mailto:#{@list_unsubscribe_email}>" if (@list_unsubscribe_email = [:list_unsubscribe_email]) @fax_unsubscribe_link = [:fax_unsubscribe_link] if .present? ['List-Unsubscribe'] = .join(",") # RFC 8058: enables Gmail/Apple/Yahoo native one-click Unsubscribe, which # POSTs to the https URL above (Www::EmailPreferencesController#one_click_unsubscribe). # Only valid when that https URL is present — a mailto alone can't be one-click. ['List-Unsubscribe-Post'] = 'List-Unsubscribe=One-Click' if @list_unsubscribe_link.present? 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 # Dev/staging campaign blasts are captured by mailpit (the env-level default # delivery target) like every other email — no per-message delivery_method # override needed. Browse them in the mailpit UI (config.x.mailpit_url). x_smtpapi = SendgridSmtpApi.build_x_smtpapi_header( unique_args: [:unique_id].present? ? { unique_id: [:unique_id] } : nil, disabled_filters: disabled_filters.presence ) Rails.logger.debug { "[CommunicationMailer] X-SMTPAPI: #{x_smtpapi}" } if Rails.env.development? headers['X-SMTPAPI'] = x_smtpapi mail() end |