Refactor contact mailer

- Send single email with new email in `to` and old email in `bcc` fields
- Remove `Que::Mailer` (#895)
- Add preview
- DRY templates
- Add tests
- Extract translations
- Remove useless specs
This commit is contained in:
Artur Beljajev 2019-04-07 17:02:43 +03:00
parent 6fa1ce9128
commit 5674071838
12 changed files with 122 additions and 125 deletions

View file

@ -1,36 +1,12 @@
class ContactMailer < ApplicationMailer
include Que::Mailer
helper_method :address_processing
def email_updated(old_email, email, contact_id, should_deliver)
@contact = Contact.find_by(id: contact_id)
def email_changed(contact:, old_email:)
@contact = contact
@old_email = old_email
unless @contact
Rails.logger.info "Cannot send email in #{self.class.name}##{__method__} with contact_id #{contact_id}. It cannot be found"
return
end
return unless email || @contact
return if delivery_off?(@contact, should_deliver)
begin
mail(to: format(email), subject: "#{I18n.t(:contact_email_update_subject)} [#{@contact.code}]")
rescue EOFError,
IOError,
TimeoutError,
Errno::ECONNRESET,
Errno::ECONNABORTED,
Errno::EPIPE,
Errno::ETIMEDOUT,
Net::SMTPAuthenticationError,
Net::SMTPServerBusy,
Net::SMTPFatalError,
Net::SMTPSyntaxError,
Net::SMTPUnknownError,
OpenSSL::SSL::SSLError => e
logger.info "EMAIL SENDING FAILED: #{email}: #{e}"
end
subject = default_i18n_subject(contact_code: contact.code)
mail(to: contact.email, bcc: old_email, subject: subject)
end
private
@ -38,4 +14,4 @@ class ContactMailer < ApplicationMailer
def address_processing
Contact.address_processing?
end
end
end