Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/errors/email_delivery_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class EmailDeliveryError < StandardError; end
11 changes: 11 additions & 0 deletions app/mailers/core_application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@ def send_custom_email(recipient:, subject:, body_html:)
# Make the request and handle the response
response = http.request(request)

unless response.is_a?(Net::HTTPSuccess)
raise EmailDeliveryError,
"Email API failed (#{response.code}): #{response.body}"
end

Rails.logger.info "Email API Response: #{response.code} - #{response.body}"
rescue Net::OpenTimeout, Net::ReadTimeout => e
raise EmailDeliveryError, "Email API timeout: #{e.message}"
rescue SocketError, Errno::ECONNREFUSED => e
raise EmailDeliveryError, "Email API connection error: #{e.message}"
rescue JSON::ParserError => e
raise EmailDeliveryError, "Email API response parsing error: #{e.message}"
end

private
Expand Down
14 changes: 0 additions & 14 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,6 @@ def self.parent_name

# Mailer configuration for inquiries/requests
config.limes_mail_server_endpoint = ENV["LIMES_MAIL_SERVER_API_ENDPOINT"]
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
domain: ENV['MONSOON_DASHBOARD_MAIL_DOMAIN'],
address: ENV['MONSOON_DASHBOARD_MAIL_SERVER'],
port: ENV['MONSOON_DASHBOARD_MAIL_SERVER_PORT'] || 25,
user_name: ENV['MONSOON_DASHBOARD_MAIL_USER'],
password: ENV['MONSOON_DASHBOARD_MAIL_PASSWORD'],
authentication: ENV['MONSOON_DASHBOARD_MAIL_AUTHENTICATION'] || 'plain',
enable_starttls_auto: true
}
config.action_mailer.default_options = {
from: ENV['MONSOON_DASHBOARD_MAIL_SENDER'].to_s
}

config.middleware.use SessionCookiePathMiddleware
config.middleware.insert_after ::Rack::Runtime, SameSiteCookieMiddleware
Expand Down
5 changes: 0 additions & 5 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@
# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

config.action_mailer.perform_caching = false

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

Expand Down
6 changes: 0 additions & 6 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "monsoon_dashboard_production"

config.action_mailer.perform_caching = false

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
Expand Down
6 changes: 0 additions & 6 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
# Store uploaded files on the local file system in a temporary directory.
config.active_storage.service = :test

config.action_mailer.perform_caching = false

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
config.active_job.queue_adapter = :test

# Print deprecation notices to the stderr.
Expand Down
43 changes: 10 additions & 33 deletions plugins/inquiry/app/models/inquiry/inquiry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ def get_callback_action
end
end

# Note: for testing use 'deliver_now'
def notify_requester
# puts "######### NOTIFY REQUESTER #########"
begin
Expand All @@ -404,8 +403,8 @@ def notify_requester
self.requester.full_name,
self,
self.process_steps.last,
).deliver_later
rescue Net::SMTPError => e
)
rescue EmailDeliveryError => e
Rails.logger.error "InquiryMailer: Could not send email to requester #{@user_email}. Exception: #{e.message}"
end
end
Expand All @@ -420,8 +419,8 @@ def notify_new_project
inform_new_project_dl,
self,
self.requester.full_name,
).deliver_later
rescue Net::SMTPError => e
)
rescue EmailDeliveryError => e
Rails.logger.error "InquiryMailer: Could not send email to #{inform_new_project_dl} Exception: #{e.message}"
end
end
Expand All @@ -436,20 +435,9 @@ def notify_additional_recipients
self,
self.process_steps.last,
self.requester,
).deliver_later
rescue Net::SMTPError => e
emails.each do |email|
begin
InquiryMailer.notification_email_additional_recipients(
[email],
self,
self.process_steps.last,
self.requester,
).deliver_later
rescue Net::SMTPError => ex
Rails.logger.error "InquiryMailer: Could not send email to #{email} Exception: #{e.message}"
end
end
)
rescue EmailDeliveryError => e
Rails.logger.error "InquiryMailer: Could not send email to additional recipients #{self.additional_recipients}. Exception: #{e.message}"
end
end

Expand All @@ -461,20 +449,9 @@ def notify_processors
self,
self.process_steps.last,
self.requester,
).deliver_later
rescue Net::SMTPError => e
self.processors.each do |p|
begin
InquiryMailer.notification_email_processors(
[p.email],
self,
self.process_steps.last,
self.requester,
).deliver_later
rescue Net::SMTPError => ex
Rails.logger.error "InquiryMailer: Could not send email to requester #{p.email}. Exception: #{ex.message}"
end
end
)
rescue EmailDeliveryError => e
Rails.logger.error "InquiryMailer: Could not send email to processors #{(self.processors.map { |p| p.email }).compact}. Exception: #{e.message}"
end
end

Expand Down
Loading