class CampaignMailer < ApplicationMailer layout false def outreach(recipient, html:, subject:) mailing = recipient.mailing identity = mailing.mail_identity html = Mailings::InlineImages.call(self, html) mailing.files.each do |file| attachments[file.filename.to_s] = { mime_type: file.content_type, content: file.download } end mail( from: identity.from_header, to: recipient.email, reply_to: identity.reply_to.presence, subject: subject, delivery_method_options: identity.smtp_settings ) do |format| format.html { render html: wrap_html(html).html_safe } end end private def wrap_html(html) return html if html.to_s.match?(/]/i) <<~HTML #{html} HTML end end