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

Email Templates #105

Open
note89 opened this issue Aug 25, 2016 · 2 comments
Open

Email Templates #105

note89 opened this issue Aug 25, 2016 · 2 comments

Comments

@note89
Copy link

note89 commented Aug 25, 2016

Hi im trying to get email templates to work but without success.

  email_reset_password_template: App.EmailTemplate.reset,

gives me this

$ mix phoenix.server
** (Mix.Config.LoadError) could not load config config/config.exs
    ** (UndefinedFunctionError) function App.EmailTemplate.reset/0 is undefined (module App.EmailTemplate is not available)
    App.EmailTemplate.reset()
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (stdlib) erl_eval.erl:878: :erl_eval.expr_list/6
    (stdlib) erl_eval.erl:236: :erl_eval.expr/5
    (stdlib) erl_eval.erl:228: :erl_eval.expr/5
    (stdlib) erl_eval.erl:229: :erl_eval.expr/5
    (stdlib) erl_eval.erl:878: :erl_eval.expr_list/6
    (stdlib) erl_eval.erl:236: :erl_eval.expr/5

this compiles

  email_reset_password_template: {App.EmailTemplate, :reset},

But gives me this runtime exception.

[error] #PID<0.457.0> running App.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /recover_password
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in EEx.Tokenizer.tokenize/5
        (eex) lib/eex/tokenizer.ex:27: EEx.Tokenizer.tokenize({App.EmailTemplate, :reset}, 1, [trim: false], [], [])
        (eex) lib/eex/compiler.ex:16: EEx.Compiler.compile/2
        (eex) lib/eex.ex:192: EEx.eval_string/3
        lib/addict/mailers/mail_sender.ex:21: Addict.Mailers.MailSender.send_reset_token/3
        lib/addict/interactors/send_reset_password_link.ex:16: Addict.Interactors.SendResetPasswordEmail.call/2
        lib/addict/controller.ex:83: Addict.AddictController.recover_password/2
        lib/addict/controller.ex:1: Addict.AddictController.action/2
        lib/addict/controller.ex:1: Addict.AddictController.phoenix_controller_pipeline/2
        (app) lib/phoenix/router.ex:261: App.Router.dispatch/2
        (app) web/router.ex:1: App.Router.do_call/2
        (app) lib/app/endpoint.ex:1: App.Endpoint.phoenix_pipeline/1
        (app) lib/plug/debugger.ex:122: App.Endpoint."call (overridable 3)"/2
        (app) lib/phoenix/endpoint/render_errors.ex:34: App.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

Here is my file
controllers/email_templates.ex

defmodule App.EmailTemplate do
  def reset do
    host = Addict.Configs.host || "http://localhost:4000"
    """
    <p> You have requested a password reset. </p>
    <p> Follow the link below and set a new password </p>
    <p> Click <a href='#{host}<%= path %>'>here</a> to proceed!</p>
    <p> Test <%= name %>, </p>
    <p> <a href="https://xkcd.com/936/" tabindex="-1" target="_blank" style="font-style: italic;">How to pick a password</a></p>
    """
  end
end
@simonh1000
Copy link

I can replicate all these errors, but also cannot see what to do next. This a real problem as the only other way seeming to override the default text is to add to config.exs something like

email_reset_password_template: "<p>Welcome to the Business Center!<br>  A new user account has been created for you (or your password has been reset). 
Please click <a href='#{host}<%= path %>'>here</a> to proceed!</p>",

But this will not compile because of the #{host}.

Any thoughts @trenpixster ?

@jeffdeville
Copy link
Contributor

I've got the same problem with another project. The problem is that the config.exs is parsed before anything else is compiled. So your first effort:

email_reset_password_template: App.EmailTemplate.reset,

fails because that function doesn't yet exist.

I haven't read the source, but the second one fails either because addict needs to know to use Kernel.apply with your arguments, or because that function is not available from addict, even though it is within the context of your entire application (which is where I'm presently floundering)

I'm still sifting around for a solution.

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

3 participants