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

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews