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
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
}
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
** (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
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