mikker / passwordless

πŸ— Authentication for your Rails app without the icky-ness of passwords
MIT License
1.25k stars 86 forks source link

Allow from address to fall back to parent mailer #187

Closed djfpaagman closed 7 months ago

djfpaagman commented 7 months ago

I'm in a situation where I want the parent mailer class to set the from address.

The use case is that based on the I18n.locale we set a different from address/domain.

Right now it's not possible to do this, as even with nil for default_from_address it will not fall back to the parent (the mailer will fail: ArgumentError (SMTP From address may not be blank)). That basically means only one, fixed from address is supported.

I've come up with a small PR that makes that work by not setting the default value if it's nil.

Curious to hear what you think, I'm not entirely sure about:

Happy to take it in the direction you want with some pointers 😁

djfpaagman commented 7 months ago

While writing this PR I had another look at my code and realized I can just put a lambda with a method call in the initializer as well:

config.default_from_address = -> { mailer_from }

This works as long as that method exists in the parent mailer, it's the same I do there to set up the default.

I want to keep this PR open though, still think it would be a nice addition!

mikker commented 7 months ago

The tests look like they're failing. I appreciate your efforts and it looks like a good solution - however, I'm hesitant to add code to solve a problem we already, as you noted, has sort of a solution for.

djfpaagman commented 7 months ago

Yeah I'm fine with it working with the lambda now, i'll close this PR 🀘

mikker commented 7 months ago

Thanks!