mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 17:28:18 +02:00
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:
parent
6fa1ce9128
commit
5674071838
12 changed files with 122 additions and 125 deletions
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue