https://github.com/railsware/mailtrap-elixir
The official mailtrap.io Elixir client
https://github.com/railsware/mailtrap-elixir
elixir email mail mailtrap-io
Last synced: 3 months ago
JSON representation
The official mailtrap.io Elixir client
- Host: GitHub
- URL: https://github.com/railsware/mailtrap-elixir
- Owner: railsware
- License: mit
- Created: 2023-01-20T18:36:45.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-13T13:09:25.000Z (about 2 years ago)
- Last Synced: 2024-03-15T02:51:58.134Z (about 1 year ago)
- Topics: elixir, email, mail, mailtrap-io
- Language: Elixir
- Homepage: https://mailtrap.io
- Size: 167 KB
- Stars: 1
- Watchers: 17
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Mailtrap
[](https://github.com/kalys/elixir-mailtrap/actions/workflows/elixir.yml)
[](https://hex.pm/packages/mailtrap)
[](https://hexdocs.pm/mailtrap/)
[](https://hex.pm/packages/mailtrap)
[](https://github.com/kalys/elixir-mailtrap/blob/master/LICENSE.md)
[](https://github.com/kalys/elixir-mailtrap/commits/master)Mailtrap API client
Bamboo adapters for Mailtrap Sandbox and Mailtrap Sending APIs## Installation
```elixir
def deps do
[
{:mailtrap, "~> 0.1.0"}
]
end
```## Configuration
For Mailtrap Sandbox Bamboo adapter
```elixir
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
```elixir
config :test_mailtrap, TestMailtrap.Mailer,
adapter: Bamboo.MailtrapSendingAdapter,
api_token: "PASTE TOKEN HERE"
```## Usage
Mailtrap API
```elixir
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
```elixir
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
```elixir
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
```elixir
# 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: "Thanks for joining!",
text_body: "Thanks for joining!"
)
end# send
welcome_email() |> TestMailtrap.Mailer.deliver_now()
```Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at .## Copyright and License
Copyright (c) 2023 Railsware Products Studio LLC
This library is released under the MIT License. See the [LICENSE.md](./LICENSE.md) file.