Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle net-smtp mail dependency error for Ruby 3.1 #44600

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion actionmailbox/app/models/action_mailbox/inbound_email.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "mail"
require "action_mailbox/mail_with_error_handling"

module ActionMailbox
# The +InboundEmail+ is an Active Record that keeps a reference to the raw email stored in Active Storage
Expand Down
2 changes: 1 addition & 1 deletion actionmailbox/lib/action_mailbox/mail_ext.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "mail"
require "action_mailbox/mail_with_error_handling"

# The hope is to upstream most of these basic additions to the Mail gem's Mail object. But until then, here they lay!
Dir["#{File.expand_path(File.dirname(__FILE__))}/mail_ext/*"].each { |path| require "action_mailbox/mail_ext/#{File.basename(path)}" }
10 changes: 10 additions & 0 deletions actionmailbox/lib/action_mailbox/mail_with_error_handling.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

begin
require "mail"
rescue LoadError => error
if error.message.match?(/net-stmp/)
$stderr.puts "You don't have net-stmp installed in your application. Please add it to your Gemfile and run bundle install"
raise
end
end
2 changes: 1 addition & 1 deletion actionmailer/lib/action_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module ActionMailer
def self.eager_load!
super

require "mail"
require "action_mailer/mail_with_error_handling"
Mail.eager_autoload!
end
end
Expand Down
2 changes: 1 addition & 1 deletion actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "mail"
require "action_mailer/mail_with_error_handling"
require "action_mailer/collector"
require "active_support/core_ext/string/inflections"
require "active_support/core_ext/hash/except"
Expand Down
10 changes: 10 additions & 0 deletions actionmailer/lib/action_mailer/mail_with_error_handling.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

begin
require "mail"
rescue LoadError => error
if error.message.match?(/net-stmp/)
$stderr.puts "You don't have net-stmp installed in your application. Please add it to your Gemfile and run bundle install"
raise
end
end