An adapter that sends email using the TurboSMTP API.
For reference: TurboSMTP API docs
This adapter requires an API Client. Swoosh comes with Hackney, Finch and Req out of the box. See the installation section for details.
Example
# config/config.exs
config :sample, Sample.Mailer,
adapter: Swoosh.Adapters.TurboSMTP,
consumer_key: "my-consumer-key",
consumer_secret: "my-consumer-secret"
# lib/sample/mailer.ex
defmodule Sample.Mailer do
use Swoosh.Mailer, otp_app: :sample
endSending from the EU region
TurboSMTP serves the EU from a separate host. Point base_url at it:
config :sample, Sample.Mailer,
adapter: Swoosh.Adapters.TurboSMTP,
consumer_key: "my-consumer-key",
consumer_secret: "my-consumer-secret",
base_url: "https://api.eu.turbo-smtp.com/api/v2"Inline images
Use Swoosh's usual inline attachments. The adapter takes care of a TurboSMTP
quirk on the way out: the API builds each inline part's Content-ID as
<content_id@sender-domain>, so a bare cid: reference never matches and the
image arrives as an ordinary attachment. References are qualified with the
sender's domain automatically, so this renders inline:
import Swoosh.Email
new()
|> from("nora@example.com")
|> to("shushu@example.com")
|> subject("Hello, Wally!")
|> html_body(~s|<img src="cid:logo.png">|)
|> attachment(Swoosh.Attachment.new("/data/logo.png", type: :inline))A cid that already carries a domain is left alone.
Using with provider options
import Swoosh.Email
new()
|> from("nora@example.com")
|> to("shushu@example.com")
|> subject("Hello, Wally!")
|> text_body("Hello")
|> put_provider_option(:reference_id, "3a1f9d7e-0c4b-4f3a-9c1e-2b6d5a7f8e90")
|> put_provider_option(:campaign_id, "welcome-2024")Provider Options
reference_id(string) -reference_id, a UUID of your own that TurboSMTP echoes back on delivery eventscampaign_id(string) -X-campaign-ID, groups sends in the dashboardmime_raw(string) -mime_raw, a complete MIME message to send verbatim
Display names in recipients
TurboSMTP splits to, cc and bcc on commas before it parses RFC 5322
quoted strings, so a comma inside a recipient's display name is torn apart and
the send is rejected. The adapter returns {:error, {:invalid_recipient, name}}
for that case rather than letting the API answer with a parse error naming a
fragment of the name. from and reply_to are not comma-split and accept it.
Summary
Functions
Callback implementation for Swoosh.Adapter.deliver/2.
Callback implementation for Swoosh.Adapter.validate_config/1.
Callback implementation for Swoosh.Adapter.validate_dependency/0.
Functions
Callback implementation for Swoosh.Adapter.deliver/2.
Callback implementation for Swoosh.Adapter.validate_config/1.
Callback implementation for Swoosh.Adapter.validate_dependency/0.