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 bodies are blank #22

Closed
MatthewRDodds opened this issue Sep 19, 2016 · 8 comments
Closed

Email bodies are blank #22

MatthewRDodds opened this issue Sep 19, 2016 · 8 comments
Labels

Comments

@MatthewRDodds
Copy link

MatthewRDodds commented Sep 19, 2016

Trying to use sentinel for invitations, I've been trying for quite awhile to get this working. At first the emails weren't sending at all, but I figured out the send_emails param and after setting that emails are sending but the email body is blank for both html and text formats.

This is my config:

config :guardian, Guardian,
  issuer: "MyApp",
  ttl: { 30, :days },
  verify_issuer: true,
  secret_key: System.get_env("SECRET_KEY"),
  serializer: MyApp.GuardianSerializer

config :guardian_db, GuardianDb,
  repo: MyApp.Repo

config :sentinel,
  app_name: "MyApp",
  user_model: MyApp.User,
  email_sender: "support@my_app.com",
  crypto_provider: Comeonin.Bcrypt,
  repo: MyApp.Repo,
  invitable: :true,
  endpoint: MyApp.Endpoint,
  router: MyApp.Router,
  send_emails: true,
  environment: :development

config :sentinel, Sentinel.Mailer,
  adapter: Bamboo.LocalAdapter

config :my_app, MyApp.Mailer,
  adapter: Bamboo.LocalAdapter

This is how I'm triggering it:

Sentinel.UserRegistration.register(%{ "user" => %{ "email" => email } })
@britton-jb
Copy link
Owner

Thanks for sending this my way. I'll see if I can take a look at it in the next couple days.

Depending on if you need API support or not you may also want to look at Coherence.

@MatthewRDodds
Copy link
Author

MatthewRDodds commented Sep 20, 2016

Thanks! I was hoping it was just a configuration problem. I might go back to where the email is converted to html/text and see whether that's where it fails, will update here with what I find.

@MatthewRDodds
Copy link
Author

MatthewRDodds commented Sep 20, 2016

I used iex to pry inside of confirmable_and_invitable and set up the context to render the template, this is what that looked like:

email = Mailer.send_invite_email(updated_user, {confirmation_token, password_reset_token})
template = email.private.view_template
assigns = email.assigns
IEx.pry

I noticed in the source for bamboo that the template is rendered this way Phoenix.View.render_to_string(email.private.view_module,template,assigns)

So I did that used that to try the render, which gave the this stack-trace:

** (Protocol.UndefinedError) protocol Phoenix.Param not implemented for []
     (phoenix) lib/phoenix/param.ex:125: Phoenix.Param.Any.to_param/1
    (myapp) web/router.ex:1: MyApp.Router.Helpers.user_path/4
    (myapp) web/router.ex:1: MyApp.Router.Helpers.user_url/4
    (sentinel) lib/sentinel/templates/email/invite.html.eex:6: Sentinel.EmailView."invite.html"/1
     (phoenix) lib/phoenix/view.ex:335: Phoenix.View.render_to_iodata/3
     (phoenix) lib/phoenix/view.ex:342: Phoenix.View.render_to_string/3
      (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
         (iex) lib/iex/evaluator.ex:135: IEx.Evaluator.handle_eval/6
         (iex) lib/iex/evaluator.ex:128: IEx.Evaluator.do_eval/4
         (iex) lib/iex/evaluator.ex:108: IEx.Evaluator.eval/4
         (iex) lib/iex/evaluator.ex:27: IEx.Evaluator.loop/3
         (iex) lib/iex/evaluator.ex:18: IEx.Evaluator.init/3
         (iex) lib/iex.ex:439: IEx.pry/3

After looking in the invite.html template I copied this line into iex which resulted in the same stacktrace, so that seems to be the source of my problem:

Sentinel.RouterHelper.helpers.user_url(Sentinel.RouterHelper.endpoint, :invited)

@MatthewRDodds
Copy link
Author

MatthewRDodds commented Sep 20, 2016

I was able to solve of that error by changing my invited path in my router from get "/users/:id/invited", UserController, :invited to get "/users/invited", UserController, :invited. Now the template renders, but still without any invite link:

pry(1)> Phoenix.View.render_to_string(email.private.view_module,template,assigns)
"<p>Hello matthewrusselldodds@gmail.com!</p>\n\n<p>You've been invited to MyApp</p>\n"

@britton-jb
Copy link
Owner

@MatthewRDodds sorry about the delay, I haven't forgotten about this. My schedule has finally permitted me to take a look. I'm able to replicate the issue, and I'm working on a fix for it. Unfortunately as you can likely guess I don't have a timeframe on it just yet.

@MatthewRDodds
Copy link
Author

No worries, thanks for the update @britton-jb! I ended up going ahead and writing my own app specific invite routine. Maybe it was something to do with my local configuration or implementation, in that case it might be good to close this for now and see if other people have trouble.

@britton-jb
Copy link
Owner

Unfortunately this is definitely a bug that I need to fix and include a spec for, based on my testing. Thanks for letting me know, and I'm glad you were able to find a workaround in the meantime.

@britton-jb britton-jb added the bug label Oct 3, 2016
@britton-jb
Copy link
Owner

Fixed in the v2 branch, which should have a 2.0.0 release in the coming week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants