Rescue contact registrant change email delivery #2745

This commit is contained in:
Priit Tark 2015-07-21 16:34:43 +03:00
parent 029dd167f5
commit 1143e16354
4 changed files with 50 additions and 24 deletions

View file

@ -1,4 +1,25 @@
class ApplicationMailer < ActionMailer::Base
default from: 'noreply@internet.ee'
layout 'mailer'
def whitelist_blocked?(emails)
return false if Rails.env.production? || Rails.env.test?
emails = [emails] unless emails.is_a?(Array)
emails = emails.flatten
emails.each do |email|
next unless TEST_EMAILS.include?(email)
logger.warn "EMAIL SENDING WAS BLOCKED BY WHITELIST: #{email}"
return true
end
false
end
# turn on delivery on specific (epp) request only, thus rake tasks does not deliver anything
def delivery_off?(model)
return false if model.deliver_emails == true
logger.warn "EMAIL SENDING WAS NOT ACTIVATED " \
"BY MODEL OBJECT: id ##{model.try(:id)} deliver_emails returned false"
true
end
end

View file

@ -1,23 +1,34 @@
class ContactMailer < ApplicationMailer
# rubocop: disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/MethodLength
def email_updated(contact)
unless Rails.env.production?
return unless TEST_EMAILS.include?(contact.email) || TEST_EMAILS.include?(contact.email_was)
end
# turn on delivery on specific request only, thus rake tasks does not deliver anything
return if contact.deliver_emails != true
return if delivery_off?(contact)
@contact = contact
emails = []
emails << [@contact.email, @contact.email_was] if @contact.registrant_domains.present?
emails << @contact.domains.map(&:registrant_email) if @contact.domains.present?
emails = emails.uniq
return if whitelist_blocked?(emails)
emails.each do |email|
mail(to: email, subject: "#{I18n.t(:contact_email_update_subject)} [#{@contact.code}]")
begin
mail(to: 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.warn "EMAIL SENDING FAILED: #{email}: #{e}"
end
end
end
# rubocop: enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/MethodLength
end

View file

@ -1,10 +1,7 @@
class DomainMailer < ApplicationMailer
def registrant_pending_updated(domain)
@domain = domain
return if Rails.env.production? ? false : !TEST_EMAILS.include?(@domain.registrant_email)
# turn on delivery on specific EPP request only, thus rake tasks does not deliver anything
return if @domain.deliver_emails != true
return if delivery_off?(@domain)
if @domain.registrant_verification_token.blank?
logger.warn "EMAIL NOT DELIVERED: registrant_verification_token is missing for #{@domain.name}"
@ -21,27 +18,23 @@ class DomainMailer < ApplicationMailer
confirm_path = "#{ENV['registrant_url']}/registrant/domain_update_confirms"
@verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}"
return if whitelist_blocked?(@old_registrant.email)
mail(to: @old_registrant.email,
subject: "#{I18n.t(:domain_registrant_pending_updated_subject, name: @domain.name)} [#{@domain.name}]")
end
def registrant_updated(domain)
@domain = domain
return if Rails.env.production? ? false : !TEST_EMAILS.include?(@domain.registrant_email)
# turn on delivery on specific EPP request only, thus rake tasks does not deliver anything
return if @domain.deliver_emails != true
return if delivery_off?(@domain)
return if whitelist_blocked?(@domain.registrant_email)
mail(to: @domain.registrant_email,
subject: "#{I18n.t(:domain_registrant_updated, name: @domain.name)} [#{@domain.name}]")
end
def pending_deleted(domain)
@domain = domain
return if Rails.env.production? ? false : !TEST_EMAILS.include?(@domain.registrant_email)
# turn on delivery on specific EPP request only, thus rake tasks does not deliver anything
return if @domain.deliver_emails != true
return if delivery_off?(@domain)
if @domain.registrant_verification_token.blank?
logger.warn "EMAIL NOT DELIVERED: registrant_verification_token is missing for #{@domain.name}"
@ -58,6 +51,7 @@ class DomainMailer < ApplicationMailer
confirm_path = "#{ENV['registrant_url']}/registrant/domain_delete_confirms"
@verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}"
return if whitelist_blocked?(@old_registrant.email)
mail(to: @old_registrant.email,
subject: "#{I18n.t(:domain_pending_deleted_subject, name: @domain.name)} [#{@domain.name}]")
end

View file

@ -1,6 +1,6 @@
class InvoiceMailer < ApplicationMailer
def invoice_email(invoice, pdf)
return if Rails.env.production? ? false : !TEST_EMAILS.include?(invoice.billing_email)
return if whitelist_blocked?(invoice.billing_email)
@invoice = invoice
attachments[invoice.pdf_name] = pdf