MatOsinski

MatOsinski

Bamboo issue - no emails sent error

Hi guys! I have created a system, which will be sent info to the user’s mail (everything locally). However, I am getting this type of error

Path which I am using http://localhost:4000/dev/mailbox

I have added this to my config/configs.exs

config :rewardapp, Rewardapp.Mailer,
  adapter: Bamboo.LocalAdapter

My mailer.ex

defmodule Rewardapp.Email do
  import Bamboo.Email
  import Bamboo.Phoenix

  def rewardEmail(user) do
    base_email()
    |> to(user)
    |> subject("You were granted points!")
    |> text_body("You were granted some points! To check, log into your account!")
  end

  defp base_email() do
    new_email()
    |> from("rewardapp@gmail.com") # Set a default from
  end
end

This is the IO.inspect of my function

function:

Rewardapp.Email.rewardEmail(userEmail)
IO.inspect(Rewardapp.Email.rewardEmail(userEmail))

result:

%Bamboo.Email{
  assigns: %{},
  attachments: [],
  bcc: nil,
  cc: nil,
  from: "rewardapp@gmail.com",
  headers: %{},
  html_body: nil,
  private: %{},
  subject: "You were granted points!",
  text_body: "You were granted some points! To check, log into your account!",
  to: "kamig@gmail.com"
}

I am using bamboo v.1.5.

In my router.ex I have configured the path:

  if Mix.env() == :dev do
    scope "/dev" do
      pipe_through :browser

      #forward "/mailbox", Plug.Swoosh.MailboxPreview
      forward "/mailbox", Bamboo.SentEmailViewerPlug
    end
  end

Why am I not able to see the output in the directory localhost:4000/dev/mailbox?

Most Liked

pmangalakader

pmangalakader

You are missing this part:

defmodule MyApp.SomeControllerPerhaps do
  def send_welcome_email do
    Email.welcome_email()   # Create your email
    |> Mailer.deliver_now!() # Send your email
  end
end

Kindly check the official documentation here: GitHub - thoughtbot/bamboo at master

You have to use your Application Mailer module to deliver the emails.

In your case, try to import this on top of the Rewardapp.Email:

import Rewardapp.Mailer
....
...
# in your email fn:
def rewardEmail(user) do
    base_email()
    |> to(user)
    |> subject("You were granted points!")
    |> text_body("You were granted some points! To check, log into your account!")
    |> Mailer.deliver_now!() # to deliver immediately
  end
pmangalakader

pmangalakader

@MatOsinski Kindly look at this video here: Sending Email in Elixir with Bamboo Part 1 - YouTube

That kind of gives the step by step instructions on how to use Bamboo. Hope this helps!

Also this link: Using Bamboo to Send Emails in Phoenix - DEV Community

MatOsinski

MatOsinski

Hi @pmangalakader. I have managed to make it work. There was error with Bamboo module name. However, I do really appreciate your help!!!

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement