Hey Folks,
I’m trying to send emails with Phoenix 1.6.4 and Swoosh. I was using Bamboo in a previous app and created a test web app to play around with Swoosh. I used the hexdocs page, the Swoosh Git page and various forum posts from here as reference for setting up the mailers and emails.
I created the app as follows mix phx.new swoosh_mailer_tutorial --live.
I used the following configuration in config.exs to send mail via AmazonSES:
config :swoosh_mailer_tutorial, SwooshMailerTutorial.Mailer,
adapter: Swoosh.Adapters.AmazonSES,
api_key: "my_api_key"
I used the default mailer provided:
defmodule SwooshMailerTutorial.Mailer do
use Swoosh.Mailer, otp_app: :swoosh_mailer_tutorial
end
I copied the email creation code almost directly from the Swoosh Git readme:
defmodule SwooshMailerTutorial.SwooshEmail do
import Swoosh.Email
def welcome do
new()
|> to({"Test User", "test@user.com"})
|> from({"Dr B Banner", "hulk.smash@example.com"})
|> subject("Hello, Avengers!")
|> html_body("<h1>Hello Scott</h1>")
|> text_body("Hello Scott\n")
end
end
I then call the mailer and email creator within the PageController’s index/2 method before rendering the standard Phoenix index page:
defmodule SwooshMailerTutorialWeb.PageController do
use SwooshMailerTutorialWeb, :controller
require Logger
def index(conn, _params) do
SwooshMailerTutorial.SwooshEmail.welcome() |> SwooshMailerTutorial.Mailer.deliver()
render(conn, "index.html")
end
end
For some reason this setup produces the following error:
I’m not surer why this is happening. Why can’t my web app find SwooshMailerTutorial.Mailer.deliver/1? I had a similar issue when sending emails using Bamboo and changing SwooshMailerTutorial → SwooshMailerTutorialWeb in the mailer and email classes seemed to fix it. This makes no sense to me as the web app should have visibility of both SwooshMailerTutorial and SwooshMailerTutorialWeb. Please let me know what I’m missing.
Thanks,
Scott























