Send an email with Thinwrap (Erlang)

Send transactional email via thinwrap_notifications:send_email/2 in Erlang — one call shape for SendGrid, AWS SES, Resend and 7 more.

1. Install

{deps, [{thinwrap_notifications, "~> 1.2"}]}.

2. Send the call

Config = #{provider => sendgrid,
           api_key => list_to_binary(os:getenv("SENDGRID_API_KEY")),
           from => <<"noreply@example.com">>},

case thinwrap_notifications:send_email(Config, #{
    to => <<"user@example.com">>,
    subject => <<"Hello from Thinwrap">>,
    text => <<"Hello world">>
}) of
    %% Status is sent | queued | rejected | suppressed | unknown
    %% Id is the upstream message id, or <<>>
    {ok, #{status := Status, provider_message_id := Id}} ->
        io:format("~s ~s~n", [Status, Id]);
    {error, #{code := Code, message := Msg}} ->
        io:format("~s: ~ts~n", [Code, Msg])
end.

Same code works for all supported providers — just change the provider ID.