mirror of
https://github.com/internetee/registry.git
synced 2025-08-13 21:19:31 +02:00
BouncedMailAddress: Remove from AWS suppression list upon destroy
This commit is contained in:
parent
6304ebdbc6
commit
2af0bfdda0
4 changed files with 24 additions and 3 deletions
2
Gemfile
2
Gemfile
|
@ -93,4 +93,4 @@ group :test do
|
||||||
gem 'webmock'
|
gem 'webmock'
|
||||||
end
|
end
|
||||||
|
|
||||||
gem "aws-sdk-ses", "~> 1.37"
|
gem "aws-sdk-sesv2", "~> 1.16"
|
||||||
|
|
|
@ -155,7 +155,7 @@ GEM
|
||||||
aws-partitions (~> 1, >= 1.239.0)
|
aws-partitions (~> 1, >= 1.239.0)
|
||||||
aws-sigv4 (~> 1.1)
|
aws-sigv4 (~> 1.1)
|
||||||
jmespath (~> 1.0)
|
jmespath (~> 1.0)
|
||||||
aws-sdk-ses (1.37.0)
|
aws-sdk-sesv2 (1.16.0)
|
||||||
aws-sdk-core (~> 3, >= 3.112.0)
|
aws-sdk-core (~> 3, >= 3.112.0)
|
||||||
aws-sigv4 (~> 1.1)
|
aws-sigv4 (~> 1.1)
|
||||||
aws-sigv4 (1.2.2)
|
aws-sigv4 (1.2.2)
|
||||||
|
@ -497,7 +497,7 @@ DEPENDENCIES
|
||||||
active_interaction (~> 3.8)
|
active_interaction (~> 3.8)
|
||||||
activerecord-import
|
activerecord-import
|
||||||
airbrake
|
airbrake
|
||||||
aws-sdk-ses (~> 1.37)
|
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::SES::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