pentacent / keila

Open Source Newsletter Tool.
https://keila.io
GNU Affero General Public License v3.0
1.42k stars 79 forks source link

Read sender mail from ENV var #49

Closed pascalwengerter closed 1 year ago

pascalwengerter commented 3 years ago

Adresses #48 in a naive way

wmnnd commented 3 years ago

Hey, thanks for giving it a shot! The reason it can’t work like this is because of the way module attributes (@something) work. They are set at compile time - so at a point when the env variable is not yet available.

I suggest defining a function sender_mail/1 in Keila.Auth.Emails and instead of using System.fetch_env!/1 using Application.get_env/2 to retrieve it fom the runtime config.

I would also suggest adding a new env variable, MAILER_FROM_EMAIL in runtime.exs and use that explicitly instead of automatically using the SMTP user name. You can find the relevant bit in the runtime config here: https://github.com/pentacent/keila/blob/03317ad783df7ff51f542ad5168f6a820eab046c/config/runtime.exs#L41 In addition, you’d have to add config(:keila, Keila.Mailer, from_email: "hello@keila.io") to the default config.exs so that it will continue to work in dev and test :smiley:

pascalwengerter commented 3 years ago

Hey, thanks for giving it a shot! The reason it can’t work like this is because of the way module attributes (@something) work. They are set at compile time - so at a point when the env variable is not yet available.

I suggest defining a function sender_mail/1 in Keila.Auth.Emails and instead of using System.fetch_env!/1 using Application.get_env/2 to retrieve it fom the runtime config.

I would also suggest adding a new env variable, MAILER_FROM_EMAIL in runtime.exs and use that explicitly instead of automatically using the SMTP user name. You can find the relevant bit in the runtime config here:

https://github.com/pentacent/keila/blob/03317ad783df7ff51f542ad5168f6a820eab046c/config/runtime.exs#L41

In addition, you’d have to add config(:keila, Keila.Mailer, from_email: "hello@keila.io") to the default config.exs so that it will continue to work in dev and test 😃

Let me see if I can come up with an acceptable solution in the upcoming days(?) ;)

pascalwengerter commented 1 year ago

@wmnnd feel free to take over here, the PR has been stale for too long and I won't be able to give it attention anytime soon :/ sry!