Mail in mix with Bamboo doesnt send

Mailer.ex

defmodule Mailer do
  import Bamboo.Email

  def email do
    new_email(
      from: "mymail@gmail.com",
      to: "mymail@icloud.com",
      subject: "Movie Added",
      text_body: "A movie was added.",
      html_body: "A movie was added."
    )
  end
end

config.exs

config :somemail, MailoingMail.Mailer,
  adapter: Bamboo.GmailAdapter,
  email: "secret-email@gmail.com",
  password: "secret-password"

when I run the function, I get

iex(4)> Mailer.email
%Bamboo.Email{
  from: "...@gmail.com",
  to: "...@gmail.com",
  cc: nil,
  bcc: nil,
  subject: "Movie Added",
  html_body: "A movie was added.",
  text_body: "A movie was added.",
  headers: %{},
  attachments: [],
  assigns: %{},
  private: %{},
  blocked: false
}

but I dont receive the email, why?

Hi @spizzy I think you just needed to keep reading further into the docs. The code you’ve written simply constructs an email, but it doesn’t ask Bamboo to send it yet. From the docs:

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

I tried that, somehow always saying that deliver_now is not available or undefined

Can you show your code and the exact error?

** (exit) exited in: GenServer.call(Goth.TokenStore, {:find, {:default, "https://www.googleapis.com/auth/gmail.send", "some@gmail.com"}}, 5000)
    ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
def start(_type, _args) do
    children = [
      # add bamboo
      {Bamboo, name: CustomMail.Mailer}
    ]

    opts = [strategy: :one_for_one, name: CustomMail.Supervisor]
    Supervisor.start_link(children, opts)
  end

I have some problems with the genserver as far as I can guess from the error :confused:

Right, so the error you’re getting is that Goth.TokenStore isn’t running, not that your deliver function doesn’t exist. This indicates that your google credentials (via goth) haven’t been set up correctly. Can you print the output of mix deps ?

Looks like this same discussion is being had in the Elixir Discord, in the interest of preventing double work from community members, you might want to read that discussion also (if you are on the Discord): Discord