Closed jsjohnst closed 7 years ago
I'll try and find out more about the current options for sending emails and get back to you.
I was able to get this up and running using thoughtbot/bamboo. I'll try and submit a pull request with a sample this week if I get a chance, but here is the gist of it:
Changes in lib/my_app/mailer.ex
defmodule MyApp.Mailer do
use Bamboo.Mailer, otp_app: :my_app
@moduledoc """
A module for sending emails.
These functions are used for email confirmation and password resetting.
"""
@doc """
An email with a confirmation link in it.
This function is called by the `create` function in the user_controller.
It should send an email with the confirmation link to the user.
"""
def ask_confirm(email, link) do
confirm_url = "https://example.com/sessions/confirm_email?#{link}"
MyApp.Email.email_validation(email, confirm_url) |> deliver_now
end
end
Code inside web/email.ex
defmodule MyApp.Email do
use Bamboo.Phoenix, view: MyApp.EmailView
def email_validation(email, link) do
base_email
|> to(email)
|> subject("MyApp: New Account Validation")
|> assign(:link, link)
|> render(:email_validation)
end
defp base_email do
new_email
|> from("MyApp <no-reply@example.com>")
|> put_layout({MyApp.LayoutView, :email})
end
end
Other than the above, I just basically followed the documentation from Bamboo.
That looks cool. When it's ready, just submit the PR.
We now have a basic example here, and there are references to it in the wiki.
Rather surprised this is completely left up to the consumer of the library rather than providing a basic example. Greatly appreciate something quick to base off of and I'm pretty sure this would go a long way with other new users of the library.