I am trying to send emails using Sendgrid with Swoosh. I tried the HTTP request and sent it with Postman, it works fine. When I try to do it with Swoosh, I get the error code 400
with Nginx - Bad Request
.
How should I approach debugging this? I considered going through the library itself to understand what might be different between my request in Postman and Swoosh (since it’s unclear to me how Swoosh builds the HTTP request behind scenes).
defmodule PhoenixApp.PrepareEmail do
use Phoenix.Swoosh, view: PhoenixAppWeb.EmailView, layout: {PhoenixAppWeb.EmailView, :email_root}
def create_email(conn, email) do
new()
|> to({"someone", email})
|> from({"...name...", "...email..."})
|> reply_to({"...name...", "...email..."})
|> subject("...subject...")
|> text_body("hey there")
end
end
defmodule PhoenixApp.Mailer do
use Swoosh.Mailer, otp_app: :phoenix_app
end
defmodule PhoenixAppWeb.PageController do
use PhoenixAppWeb, :controller
def index(conn, _params) do
# Create Email
email = PhoenixApp.PrepareEmail.create_email(conn, email)
# Send Email
PhoenixApp.Mailer.deliver(email)
render(conn, "index.html")
end
end