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

Sendmail argument change breaks Rails usage of Sendmail #1538

Closed
RaymondFallon opened this issue Dec 13, 2022 · 10 comments
Closed

Sendmail argument change breaks Rails usage of Sendmail #1538

RaymondFallon opened this issue Dec 13, 2022 · 10 comments

Comments

@RaymondFallon
Copy link

I see from the CHANGELOG for v2.8.0 that the following change was made intentionally:

Sendmail and exim delivery :arguments option must be an array of string args

It was even listed as a "breaking change," so this issue is more of a question than a bug report. But I wanted to note that this change breaks how Rails' ActionMailer implements Sendmail:

add_delivery_method :sendmail, Mail::Sendmail,
  location:  "/usr/sbin/sendmail",
  arguments: "-i"

I don't know whether or not Rails applications represent a large portion of apps that use the mail gem, but in case they do, I wanted to point out this potentially high-impact breakage and confirm that it was deemed acceptable before attempting to fix things within Rails.

Thanks!


Additional info on breakage:

When attempting to deliver mail via the :sendmail method with rails 7.0.4 and mail 2.8.0, I get a runtime error like the following:

ArgumentError (:arguments expected to be an Array of individual string args):
  
/gems/mail/lib/mail/network/delivery_methods/sendmail.rb:53:in `initialize'

If the Sendmail argument signature is to stay as it is, I believe action_mailer will need to change its instantiation of :sendmail to:

add_delivery_method :sendmail, Mail::Sendmail,
  location:  "/usr/sbin/sendmail",
  arguments: "[-i]"
@eval
Copy link
Collaborator

eval commented Dec 13, 2022

Seems serious. @mikel how about a fix that doesn't raise here

raise ArgumentError, ":arguments expected to be an Array of individual string args" if settings[:arguments].is_a?(String)
but instead splits the string (and emits a warning)?

@mikel
Copy link
Owner

mikel commented Dec 13, 2022

@eval yes, that makes sense, we should make that a PR and get that deployed as 2.8.1 right away. If we get a string, split it and put it back in.

@sebbASF
Copy link
Collaborator

sebbASF commented Dec 14, 2022

Agree with restoring support for string.

However if valid arguments can contain blanks, it makes correctly splitting the string tricky.
An alternative would be to append the original string when building the command.

Whilst this would not be as safe against shell mis-interpretation, it is very unlikely that the arguments provided by callers are derived directly from user input.

As well as emitting a warning, it would be useful to document why a string is deprecated.

@kokogakayui
Copy link

Hi.

Just for the sake of feedback : mail 2.8.0 is indeed breaking my rails application in production when trying to deploy on AWS Beanstalk.

I am running ruby 3.0.5 and rails 6.1.7. Reverting back to 2.7.1 fixes it back.
Did not really find out what the error was, but something related to an uninitialized constant Mail::SendMail.

Hope this will help.

@eval eval mentioned this issue Dec 14, 2022
@eval
Copy link
Collaborator

eval commented Dec 14, 2022

However if valid arguments can contain blanks, it makes correctly splitting the string tricky.
An alternative would be to append the original string when building the command.

Good point @sebbASF. But adding an argument with spaces doesn't work either right? E.g. IO.popen(["ls", "-l -h"]) fails.
So it seems to me that when passed a string, the command should be a string.

@sebbASF
Copy link
Collaborator

sebbASF commented Dec 14, 2022

Good point, agreed

@eval
Copy link
Collaborator

eval commented Dec 14, 2022

Current draft: #1547

@sebbASF
Copy link
Collaborator

sebbASF commented Dec 14, 2022

#1547 includes changes to test.yml allow the PR to run as a GH action.

The unadorned draft is #1545

Ferenc- added a commit to instana/ruby-sensor that referenced this issue Dec 15, 2022
The latest `mail` version `2.8.0` broke the interface
that `rails` have been using:
mikel/mail#1538
Hopefully support will be restored for the old one.

Signed-off-by: Ferenc Géczi <ferenc.geczi@ibm.com>
Ferenc- added a commit to instana/ruby-sensor that referenced this issue Dec 15, 2022
The latest `mail` version `2.8.0` broke the interface
that `rails` have been using:
mikel/mail#1538
Hopefully support will be restored for the old one.

Signed-off-by: Ferenc Géczi <ferenc.geczi@ibm.com>
@pierre-alain-b
Copy link

Same here, this broke multiple production Rails apps. Reverting to 2.7.1.

eval pushed a commit to eval/mail that referenced this issue Jan 13, 2023
eval added a commit to eval/mail that referenced this issue Jan 13, 2023
@eval
Copy link
Collaborator

eval commented Jan 13, 2023

Fixed via #1545

@eval eval closed this as completed Jan 13, 2023
rsmoke added a commit to lsa-mis/mmss-mysql that referenced this issue Jan 17, 2023
The sendmail default sendmail arguments configuration value given by actionmailer is "-i". Which was fine for the older mail gem.

The new gem requires this to be an list of strings.

mikel/mail#1538

https://www.gamecreatures.com/blog/2022/12/19/
incompatibility-rails-5-2-and-mail-gem-argumenterror-arguments-expected-to-be-an-
array-of-individual-string-args/
gbp added a commit to mysociety/alaveteli that referenced this issue Jan 24, 2023
Update sendmail settings to fix argument error.

See: mikel/mail#1538
See: rails/rails#46650
gbp added a commit to mysociety/alaveteli that referenced this issue Jan 24, 2023
Update sendmail settings to fix argument error.

See: mikel/mail#1538
See: rails/rails#46650
renspr added a commit to ubpb/catalog that referenced this issue Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants