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

In generic_send_email, check if mail object responds to delivery method instead of checking inheritance from ActionMailer #211

Merged
merged 3 commits into from
Feb 24, 2020

Conversation

Plsr
Copy link
Contributor

@Plsr Plsr commented Nov 22, 2019

What changed

  • generic_send_email now checks if the created mail object responds to the configured delivery method and attempts to send out the message if this is true. (Was checking for inheritance from ActionMailer::Base before)
  • Added an empty manifest.js in the rails app in specs. Not having this would cause errors running bundle exec rake with sprockets 4 (happy to remove this if this is just a problem with my configuration)

Why?

In one of our projects, we are using the mandrill_mailer gem to send out mails with MailChimp. mandrill_mailer does not inherit from ActionMailer, but implements all its delivery methods to mimic its behavior. It took us quite a while to find out why out mails were not being sent by sorcery.

Since the user is required to configure a "Mailer" and pass it to sorcery and also can configure not to automatically send out messages, I would expect sorcery to send out messages if they are sendable, no matter the communication channel.

Feedback

From what I can see in the version history, this inheritance check has been there from the first commit and was just loosened up a little in 2012 (ab97a3f#diff-ae4a62ce1fc7636933767432515a82bdR187). Since the check was pretty explicit, I don't know what side effects this change might have and if I'm overlooking anything here.

Also I'm not sure if this might be a breaking change for some users, as it could trigger sending out messages twice, based on the configuration.

Looking forward to hear your thoughts on this!

Instead of checking for an inheritance of ActionMailer::Base,
just see if the conffigure mailer and method respond to the configured
delivery method.

Since both the mailer and the willingniess to automatically send out
messages can be configured, the message should be send if it is
sendable, regardless of which Class the configured mailer inherits
from.
Not having a manifest was causing issues running `bundle exec rake`
with sprockets 4.
@mladenilic
Copy link
Contributor

I agree with this change.

it could trigger sending out messages twice, based on the configuration.

I'm not sure what do you mean by this?

P.S. build should now be fixed (5ac8d62)

@Plsr
Copy link
Contributor Author

Plsr commented Dec 2, 2019

I was thinking of someone with a similar setup I described above that we are currently in.

Let's say SuperMailer was implementing deliver_later, but was not inheriting from ActionMailer. So, to make the automated mail delivery work in the current version of sorcery, people may do something like

class UserMailer < SuperMailer
  def activation_needed_email
    mail_construction_method(
      # Some mail setup
    ).deliver_later
  end
end

I'm not sure if we would be breaking something with the explicit deliver_later inside the activation_needed_email function that, with the changes introduced here, would also be invoked with deliver_later.
I feel like this should not be a problem, but I'm not 100% sure about it, that's why I brought it up.

@mladenilic
Copy link
Contributor

@Plsr: Thanks for additional explanation, I see now what you mean.

I'd say that it would be enough simply to explain this in the change log, so users who were affected by this issue can now get rid of hacks.

@Plsr
Copy link
Contributor Author

Plsr commented Jan 21, 2020

Any updates on this? We are encountering the same problem once again in another project.

@stephanpavlovic
Copy link

Is there anything more needed to merge this? I'm having the same issue....

@joshbuker
Copy link
Member

Merging this into master, I think this would be a good opportunity to get @mladenilic to try their hands at the deployment process.

Hopefully we should have a new version out in the next couple days, barring that you should be able to point at the master branch to get the change in the short term.

@joshbuker joshbuker merged commit f87d14e into Sorcery:master Feb 24, 2020
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

Successfully merging this pull request may close these issues.

4 participants