mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 18:26:06 +02:00
Merge pull request #1840 from internetee/1839-remove-bounced-emails-from-amazon-ses-bounced-list
BouncedMailAddress: Remove from AWS suppression list upon destroy
This commit is contained in:
commit
8d76979856
4 changed files with 37 additions and 0 deletions
2
Gemfile
2
Gemfile
|
@ -92,3 +92,5 @@ group :test do
|
||||||
gem 'webdrivers'
|
gem 'webdrivers'
|
||||||
gem 'webmock'
|
gem 'webmock'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
gem 'aws-sdk-sesv2', '~> 1.16'
|
||||||
|
|
14
Gemfile.lock
14
Gemfile.lock
|
@ -148,6 +148,18 @@ GEM
|
||||||
attr_required (1.0.1)
|
attr_required (1.0.1)
|
||||||
autoprefixer-rails (10.0.0.2)
|
autoprefixer-rails (10.0.0.2)
|
||||||
execjs
|
execjs
|
||||||
|
aws-eventstream (1.1.0)
|
||||||
|
aws-partitions (1.424.0)
|
||||||
|
aws-sdk-core (3.112.0)
|
||||||
|
aws-eventstream (~> 1, >= 1.0.2)
|
||||||
|
aws-partitions (~> 1, >= 1.239.0)
|
||||||
|
aws-sigv4 (~> 1.1)
|
||||||
|
jmespath (~> 1.0)
|
||||||
|
aws-sdk-sesv2 (1.16.0)
|
||||||
|
aws-sdk-core (~> 3, >= 3.112.0)
|
||||||
|
aws-sigv4 (~> 1.1)
|
||||||
|
aws-sigv4 (1.2.2)
|
||||||
|
aws-eventstream (~> 1, >= 1.0.2)
|
||||||
bcrypt (3.1.16)
|
bcrypt (3.1.16)
|
||||||
bindata (2.4.8)
|
bindata (2.4.8)
|
||||||
bootsnap (1.4.8)
|
bootsnap (1.4.8)
|
||||||
|
@ -226,6 +238,7 @@ GEM
|
||||||
i18n_data (0.10.0)
|
i18n_data (0.10.0)
|
||||||
isikukood (0.1.2)
|
isikukood (0.1.2)
|
||||||
iso8601 (0.12.1)
|
iso8601 (0.12.1)
|
||||||
|
jmespath (1.4.0)
|
||||||
jquery-rails (4.4.0)
|
jquery-rails (4.4.0)
|
||||||
rails-dom-testing (>= 1, < 3)
|
rails-dom-testing (>= 1, < 3)
|
||||||
railties (>= 4.2.0)
|
railties (>= 4.2.0)
|
||||||
|
@ -484,6 +497,7 @@ DEPENDENCIES
|
||||||
active_interaction (~> 3.8)
|
active_interaction (~> 3.8)
|
||||||
activerecord-import
|
activerecord-import
|
||||||
airbrake
|
airbrake
|
||||||
|
aws-sdk-sesv2 (~> 1.16)
|
||||||
bootsnap (>= 1.1.0)
|
bootsnap (>= 1.1.0)
|
||||||
bootstrap-sass (~> 3.4)
|
bootstrap-sass (~> 3.4)
|
||||||
cancancan
|
cancancan
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class BouncedMailAddress < ApplicationRecord
|
class BouncedMailAddress < ApplicationRecord
|
||||||
validates :email, :message_id, :bounce_type, :bounce_subtype, :action, :status, presence: true
|
validates :email, :message_id, :bounce_type, :bounce_subtype, :action, :status, presence: true
|
||||||
|
after_destroy :destroy_aws_suppression
|
||||||
|
|
||||||
def bounce_reason
|
def bounce_reason
|
||||||
"#{action} (#{status} #{diagnostic})"
|
"#{action} (#{status} #{diagnostic})"
|
||||||
|
@ -25,4 +26,20 @@ class BouncedMailAddress < ApplicationRecord
|
||||||
diagnostic: bounced_record['diagnosticCode'],
|
diagnostic: bounced_record['diagnosticCode'],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy_aws_suppression
|
||||||
|
return unless BouncedMailAddress.ses_configured?
|
||||||
|
|
||||||
|
res = Aws::SESV2::Client.new.delete_suppressed_destination(email_address: email)
|
||||||
|
res.successful?
|
||||||
|
rescue Aws::SESV2::Errors::ServiceError => e
|
||||||
|
logger.warn("Suppression not removed. #{e}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.ses_configured?
|
||||||
|
ses ||= Aws::SESV2::Client.new
|
||||||
|
ses.config.credentials.access_key_id.present?
|
||||||
|
rescue Aws::Errors::MissingRegionError
|
||||||
|
false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
4
config/initializers/aws_ses.rb
Normal file
4
config/initializers/aws_ses.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
Aws.config.update(
|
||||||
|
region: ENV['aws_default_region'],
|
||||||
|
credentials: Aws::Credentials.new(ENV['aws_access_key_id'], ENV['aws_secret_access_key'])
|
||||||
|
)
|
Loading…
Add table
Add a link
Reference in a new issue