hendri-tobing

hendri-tobing

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.

Any ideas to resolve this are appreciated.

Thank you.

Showing Posts 1 to 9

wolfiton

wolfiton

Take a look here if you haven’t Bamboo.LocalAdapter — bamboo v2.5.0

This part

Example config

# 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
hendri-tobing

hendri-tobing OP

Thank you for the response. I have read and follow the documentation before, and do as you suggested, but the error is still there.

wolfiton

wolfiton

OK, start the server with:

mix phx.server

Then navigate in the browser to http://localhost:4000/sent_emails

Then copy the full error and post if on the forum.

This might make it easier to understand what is going on.

hendri-tobing

hendri-tobing OP

This is the error

00:55:34.896 [error] #PID<0.941.0> running MyWeb.Endpoint (connection #PID<0.939.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /sent_emails
** (exit) an exception was raised:
    ** (UndefinedFunctionError) function MyWeb.Bamboo.SentEmailViewerPlug.init/1 is undefined (module MyWeb.Bamboo.SentEmailViewerPlug is not available)
        MyWeb.Bamboo.SentEmailViewerPlug.init([])
        (phoenix) lib/phoenix/router/route.ex:40: Phoenix.Router.Route.call/2
        (phoenix) lib/phoenix/router.ex:288: Phoenix.Router.__call__/2
        (my_web) lib/my_web/endpoint.ex:1: MyWeb.Endpoint.plug_builder_call/2
        (my_web) lib/plug/debugger.ex:122: MyWeb.Endpoint."call (overridable 3)"/2
        (my_web) lib/my_web/endpoint.ex:1: MyWeb.Endpoint.call/2
        (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4
        (cowboy) /Users/Hendri/GitHub/datingdev/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
NobbZ

NobbZ

Can you please show us your full router.ex?

It might be that you have omitted something important…

wolfiton

wolfiton

Do you really have a space here? If so delete the space and write

forward "/sent_emails", Bamboo.SentEmailViewerPlug

Does it work now?

hendri-tobing

hendri-tobing OP

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
jg-made

jg-made

Just take it out of the scope. Move those 3 lines in your router.ex:

    if Mix.env == :dev do
      forward "/sent_emails", Bamboo.SentEmailViewerPlug  
    end

down one line (after the scope’s end) and I think it should be fine.

source: Bamboo.SentEmailViewerPlug — bamboo v2.5.0

hendri-tobing

hendri-tobing OP

Thank you. This is the solution.

Thank you also for all the responses.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews