How can I integrate Amazon SES?

I followed Swoosh docs but email doesn’t arrive.

There’s a mention about IAM role and :security_token. But I couldn’t find further information about it.

IAM role
… but you also need to include additional X-Amz-Security-Token header to that request.

You can do that by adding :security_token to :provider_options.

Other than that SES works without it.

I could send emails regardless of if I added the |> put_provider_option(:security_token, “your_token_here”) header or not.

It’s been frustrating. Please let me know if you have any idea I can make it work.

This is my config.

# config/prod.exs
config :swoosh, :api_client, Feder.Finch

# config/runtime.exs
config :feder, Feder.Mailer,
  adapter: Swoosh.Adapters.AmazonSES,
  region: "us-east-2",
  access_key: System.get_env("SMTP_ID"),
  secret: System.get_env("SMTP_SECRET")

This is AWS policy

    "Version": "2012-10-17",
    "Statement": [
            "Effect": "Allow",
            "Action": "ses:SendRawEmail",
            "Resource": "*"

I’ve got deps.

defp deps do
    {:swoosh, "~> 1.3"},
    {:finch, "~> 0.13"},
    {:gen_smtp, "~> 1.0"},

This is what server logs for requests.
    {"Authorization", "AWS4-HMAC-SHA256 Credential=A...M/20221227/us-east-2/ses/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature=e...d"}, 
    {"Content-Length", "1061"}, 
    {"Content-Type", "application/x-www-form-urlencoded"}, 
    {"Host", ""}, 
    {"X-Amz-Date", "20221227T213132Z"}
  %Swoosh.Email{ ... }

It was not AWS, it was my config. Feder is my app name.

*** config/prod.exs
- config :swoosh, :api_client, Feder.Finch
+ config :swoosh, :api_client, Swoosh.ApiClient.Finch

*** lib/feder/application.ex
- {Finch, name: Feder.Finch},
+ {Finch, name: Swoosh.Finch},

I overlooked them because, if phoenix ships with Swoosh and Finch, why would it miss the right config? It doesn’t even have options. What’s the point of <app_name>.Finch? Am I supposed to implement something like lib/<app_name>/finch.ex?

1 Like