mirror of
https://github.com/internetee/registry.git
synced 2025-07-20 17:55:55 +02:00
Rescue contact registrant change email delivery #2745
This commit is contained in:
parent
029dd167f5
commit
1143e16354
4 changed files with 50 additions and 24 deletions
|
@ -1,4 +1,25 @@
|
||||||
class ApplicationMailer < ActionMailer::Base
|
class ApplicationMailer < ActionMailer::Base
|
||||||
default from: 'noreply@internet.ee'
|
default from: 'noreply@internet.ee'
|
||||||
layout 'mailer'
|
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
|
end
|
||||||
|
|
|
@ -1,23 +1,34 @@
|
||||||
class ContactMailer < ApplicationMailer
|
class ContactMailer < ApplicationMailer
|
||||||
# rubocop: disable Metrics/CyclomaticComplexity
|
# rubocop:disable Metrics/MethodLength
|
||||||
def email_updated(contact)
|
def email_updated(contact)
|
||||||
unless Rails.env.production?
|
return if delivery_off?(contact)
|
||||||
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
|
|
||||||
|
|
||||||
@contact = contact
|
@contact = contact
|
||||||
|
|
||||||
emails = []
|
emails = []
|
||||||
emails << [@contact.email, @contact.email_was] if @contact.registrant_domains.present?
|
emails << [@contact.email, @contact.email_was] if @contact.registrant_domains.present?
|
||||||
emails << @contact.domains.map(&:registrant_email) if @contact.domains.present?
|
emails << @contact.domains.map(&:registrant_email) if @contact.domains.present?
|
||||||
emails = emails.uniq
|
emails = emails.uniq
|
||||||
|
|
||||||
|
return if whitelist_blocked?(emails)
|
||||||
emails.each do |email|
|
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
|
||||||
end
|
end
|
||||||
# rubocop: enable Metrics/CyclomaticComplexity
|
# rubocop:enable Metrics/MethodLength
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
class DomainMailer < ApplicationMailer
|
class DomainMailer < ApplicationMailer
|
||||||
def registrant_pending_updated(domain)
|
def registrant_pending_updated(domain)
|
||||||
@domain = domain
|
@domain = domain
|
||||||
return if Rails.env.production? ? false : !TEST_EMAILS.include?(@domain.registrant_email)
|
return if delivery_off?(@domain)
|
||||||
|
|
||||||
# turn on delivery on specific EPP request only, thus rake tasks does not deliver anything
|
|
||||||
return if @domain.deliver_emails != true
|
|
||||||
|
|
||||||
if @domain.registrant_verification_token.blank?
|
if @domain.registrant_verification_token.blank?
|
||||||
logger.warn "EMAIL NOT DELIVERED: registrant_verification_token is missing for #{@domain.name}"
|
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"
|
confirm_path = "#{ENV['registrant_url']}/registrant/domain_update_confirms"
|
||||||
@verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}"
|
@verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}"
|
||||||
|
|
||||||
|
return if whitelist_blocked?(@old_registrant.email)
|
||||||
mail(to: @old_registrant.email,
|
mail(to: @old_registrant.email,
|
||||||
subject: "#{I18n.t(:domain_registrant_pending_updated_subject, name: @domain.name)} [#{@domain.name}]")
|
subject: "#{I18n.t(:domain_registrant_pending_updated_subject, name: @domain.name)} [#{@domain.name}]")
|
||||||
end
|
end
|
||||||
|
|
||||||
def registrant_updated(domain)
|
def registrant_updated(domain)
|
||||||
@domain = domain
|
@domain = domain
|
||||||
return if Rails.env.production? ? false : !TEST_EMAILS.include?(@domain.registrant_email)
|
return if delivery_off?(@domain)
|
||||||
|
|
||||||
# turn on delivery on specific EPP request only, thus rake tasks does not deliver anything
|
|
||||||
return if @domain.deliver_emails != true
|
|
||||||
|
|
||||||
|
return if whitelist_blocked?(@domain.registrant_email)
|
||||||
mail(to: @domain.registrant_email,
|
mail(to: @domain.registrant_email,
|
||||||
subject: "#{I18n.t(:domain_registrant_updated, name: @domain.name)} [#{@domain.name}]")
|
subject: "#{I18n.t(:domain_registrant_updated, name: @domain.name)} [#{@domain.name}]")
|
||||||
end
|
end
|
||||||
|
|
||||||
def pending_deleted(domain)
|
def pending_deleted(domain)
|
||||||
@domain = domain
|
@domain = domain
|
||||||
return if Rails.env.production? ? false : !TEST_EMAILS.include?(@domain.registrant_email)
|
return if delivery_off?(@domain)
|
||||||
|
|
||||||
# turn on delivery on specific EPP request only, thus rake tasks does not deliver anything
|
|
||||||
return if @domain.deliver_emails != true
|
|
||||||
|
|
||||||
if @domain.registrant_verification_token.blank?
|
if @domain.registrant_verification_token.blank?
|
||||||
logger.warn "EMAIL NOT DELIVERED: registrant_verification_token is missing for #{@domain.name}"
|
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"
|
confirm_path = "#{ENV['registrant_url']}/registrant/domain_delete_confirms"
|
||||||
@verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}"
|
@verification_url = "#{confirm_path}/#{@domain.id}?token=#{@domain.registrant_verification_token}"
|
||||||
|
|
||||||
|
return if whitelist_blocked?(@old_registrant.email)
|
||||||
mail(to: @old_registrant.email,
|
mail(to: @old_registrant.email,
|
||||||
subject: "#{I18n.t(:domain_pending_deleted_subject, name: @domain.name)} [#{@domain.name}]")
|
subject: "#{I18n.t(:domain_pending_deleted_subject, name: @domain.name)} [#{@domain.name}]")
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class InvoiceMailer < ApplicationMailer
|
class InvoiceMailer < ApplicationMailer
|
||||||
def invoice_email(invoice, pdf)
|
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
|
@invoice = invoice
|
||||||
attachments[invoice.pdf_name] = pdf
|
attachments[invoice.pdf_name] = pdf
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue