Skip to content

railsware/mailtrap-elixir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mailtrap

Elixir CI Module Version Hex Docs Total Download License Last Updated

Mailtrap API client Bamboo adapters for Mailtrap Sandbox and Mailtrap Sending APIs

Installation

def deps do
  [
    {:mailtrap, "~> 0.1.0"}
  ]
end

Configuration

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"

Usage

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", "[email protected]"})
  |> Mailtrap.Email.put_to({"Recepient", "[email protected]"})
  |> 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", "[email protected]"})
  |> Mailtrap.Email.put_to({"Recepient", "[email protected]"})
  |> Mailtrap.Email.put_subject("Hi there")
  |> Mailtrap.Email.put_text("General Kenobi"))
Mailtrap.Sending.send(client, email)

Bamboo adapter

# 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 \\ "[email protected]") do
  new_email(
    to: {friendly_name, to},
    from: {"From", "[email protected]"},
    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 and License

Copyright (c) 2023 Railsware Products Studio LLC

This library is released under the MIT License. See the LICENSE.md file.

Releases

No releases published

Packages

No packages published

Languages