Closed djfpaagman closed 11 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!
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.
Yeah I'm fine with it working with the lambda now, i'll close this PR π€
Thanks!
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
fordefault_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:
mailer_defaults
method? Feel like it could also live in thePasswordless::Mailer
class.I've had some issues with getting all tests to run, not sure if this is correct now. Since we need to change the config just for this test, I think setting it like this and resetting at the end is the best way to do it.edit: found theWithConfig.with_config
helper that solves my problem πHappy to take it in the direction you want with some pointers π