I am working on an umbrella application that contains a separate Phoenix and Ecto application (my_web and my_app).
Then I Install the Bamboo email library for sending emails on the Phoenix App my_web. Bamboo can view the sent emails by using the Phoenix controller. I follow the configuration as described in the documentation.
# in config file (config/config.exs)
config: my_web, MyWeb.Mailer,
adapter: Bamboo.LocalAdapter
# In Router
defmodule MyWeb.Router do
if Mix.env ==: dev do
# If using Phoenix
forward "/ sent_emails", Bamboo.SentEmailViewerPlug
end
end
However, there is an error message:
MyWeb.Bamboo.SentEmailViewerPlug.init / 1 function is undefined
It is wrong because the correct one is Bamboo.SentEmailViewerPlug module, not MyWeb.Bamboo.SentEmailViewerPlug.
# In config/config.exs, or config/dev.exs, etc.
config :my_app, MyApp.Mailer,
adapter: Bamboo.LocalAdapter,
open_email_in_browser_url: "http://localhost:4000/sent_emails" # optional
# Define a Mailer. Maybe in lib/my_app/mailer.ex
defmodule MyApp.Mailer do
use Bamboo.Mailer, otp_app: :my_app
end
There is no space on the forward route. Here is the full router.ex
defmodule MyWeb.Router do
use MyWeb, :router
#use Phoenix.Router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/", MyWeb do
pipe_through [:browser, MyWeb.Plugs.Guest]
get "/", FrontPageController, :index
resources "/register", UserController, only: [:create, :new]
get "/login", SessionController, :new
post "/login", SessionController, :create
get "/verify", UserController, :verify_email_from_user
# Email Development route
if Mix.env == :dev do
forward "/sent_emails", Bamboo.SentEmailViewerPlug
end
end
scope "/", MyWeb do
pipe_through [:browser, MyWeb.Plugs.Auth]
delete "/logout", SessionController, :delete
get "/page", PageController, :index
resources "/user", UserController
end
# Other scopes may use custom stacks.
# scope "/api", MyWeb do
# pipe_through :api
# end
end