Mailtrap API client Bamboo adapters for Mailtrap Sandbox and Mailtrap Sending APIs
def deps do
[
{:mailtrap, "~> 0.1.0"}
]
end
For Mailtrap Sandbox Bamboo adapter
config :test_mailtrap, TestMailtrap.Mailer,
adapter: Bamboo.MailtrapSandboxAdapter,
api_token: "PASTE TOKEN HERE",
inbox_id: 111 # replace with your inbox id
For Mailtrap Sending Bamboo adapter
config :test_mailtrap, TestMailtrap.Mailer,
adapter: Bamboo.MailtrapSendingAdapter,
api_token: "PASTE TOKEN HERE"
Mailtrap API
client = Mailtrap.client("PASTE TOKEN HERE")
accounts = Mailtrap.get(client, "accounts")
# or
Mailtrap.delete(client, "accounts/" <> account_id <> "/account_accesses/" <> account_access_id)
Sending to Mailtrap Sandbox API
client = Mailtrap.Sandbox.client("PASTE TOKEN HERE")
email = (%Mailtrap.Email{}
|> Mailtrap.Email.put_from({"From name", "from@example.com"})
|> Mailtrap.Email.put_to({"Recepient", "recepient@example.com"})
|> Mailtrap.Email.put_subject("Hi there")
|> Mailtrap.Email.put_text("General Kenobi"))
Mailtrap.Sandbox.send(client, email, 111) # replace 111 with your inbox id
Sending via Mailtrap Sending API
client = Mailtrap.Sending.client("PASTE TOKEN HERE")
email = (%Mailtrap.Email{}
|> Mailtrap.Email.put_from({"From name", "from@example.com"})
|> Mailtrap.Email.put_to({"Recepient", "recepient@example.com"})
|> Mailtrap.Email.put_subject("Hi there")
|> Mailtrap.Email.put_text("General Kenobi"))
Mailtrap.Sending.send(client, email)
# mailer module
defmodule TestMailtrap.Mailer do
use Bamboo.Mailer, otp_app: :test_mailtrap
end
# generate email
def welcome_email(subject \\ "Hi there", friendly_name \\ "Recepient", to \\ "recepient@example.com") do
new_email(
to: {friendly_name, to},
from: {"From", "from@example.com"},
subject: subject,
html_body: "<strong>Thanks for joining!</strong>",
text_body: "Thanks for joining!"
)
end
# send
welcome_email() |> TestMailtrap.Mailer.deliver_now()
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/mailtrap.
Copyright (c) 2023 Railsware Products Studio LLC
This library is released under the MIT License. See the LICENSE.md file.