MVP
This commit is contained in:
commit
5b66cde5bc
|
@ -0,0 +1,4 @@
|
|||
# Used by "mix format"
|
||||
[
|
||||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Created by https://www.toptal.com/developers/gitignore/api/elixir
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=elixir
|
||||
|
||||
### Elixir ###
|
||||
/_build
|
||||
/cover
|
||||
/deps
|
||||
/doc
|
||||
/.fetch
|
||||
erl_crash.dump
|
||||
*.ez
|
||||
*.beam
|
||||
/config/*.secret.exs
|
||||
.elixir_ls/
|
||||
|
||||
### Elixir Patch ###
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/elixir
|
|
@ -0,0 +1,39 @@
|
|||
# Swoosh Mailinator
|
||||
|
||||
This project is an adapter for swoosh that relais any email to the Mailinator.com SMTP server, no mater the internet domain of the recipient.
|
||||
|
||||
This service provide no encryption in transit (SSL/TLS) nor authentication.
|
||||
|
||||
This service provide public access to mailboxes.
|
||||
|
||||
Don't use this adapter for confidential information.
|
||||
|
||||
Use for tests only.
|
||||
|
||||
## Installation
|
||||
|
||||
This module can be installed by adding `swoosh_mailinator` to your list of dependencies in `mix.exs`:
|
||||
|
||||
```elixir
|
||||
def deps do
|
||||
[
|
||||
{:swoosh_mailinator, "~> 0.1.0", git: "https://git.zoocoop.com/setop/swoosh_mailinator"}
|
||||
]
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```elixir
|
||||
# config/config.exs
|
||||
config :sample, Sample.Mailer,
|
||||
adapter: Swoosh.Adapters.Mailinator
|
||||
|
||||
# lib/sample/mailer.ex
|
||||
defmodule Sample.Mailer do
|
||||
use Swoosh.Mailer, otp_app: :sample
|
||||
end
|
||||
```
|
||||
|
||||
see also [test/swoosh_mlntr.exs](test/swoosh_mlntr.exs)
|
|
@ -0,0 +1,61 @@
|
|||
defmodule Swoosh.Adapters.Mailinator do
|
||||
|
||||
@moduledoc ~S"""
|
||||
An adapter that sends email to Mailinator.com service using the SMTP protocol.
|
||||
|
||||
Underneath this adapter uses the
|
||||
[gen_smtp](https://github.com/gen-smtp/gen_smtp) library, add it to your mix.exs file.
|
||||
|
||||
## Example
|
||||
|
||||
# mix.exs
|
||||
def deps do
|
||||
[
|
||||
{:swoosh, "~> 1.3"},
|
||||
{:gen_smtp, "~> 1.1"}
|
||||
]
|
||||
end
|
||||
|
||||
# config/config.exs
|
||||
config :sample, Sample.Mailer,
|
||||
adapter: Swoosh.Adapters.Mailinator
|
||||
|
||||
# lib/sample/mailer.ex
|
||||
defmodule Sample.Mailer do
|
||||
use Swoosh.Mailer, otp_app: :sample
|
||||
end
|
||||
|
||||
## Note
|
||||
|
||||
This adatper relay the email to the Mailinator.com SMTP server, no mater the internet domain of the recipient.
|
||||
|
||||
This service provide no encryption in transit (SSL/TLS) nor authentication.
|
||||
|
||||
This service provide public access to mailboxes.
|
||||
|
||||
Don't use this adapter for confidential information.
|
||||
|
||||
Use for tests only.
|
||||
|
||||
TODO: allow to choose from Text or HTML :prefer_html, :prefer_text
|
||||
"""
|
||||
|
||||
use Swoosh.Adapter, required_config: []
|
||||
|
||||
alias Swoosh.Email
|
||||
alias Swoosh.Mailer
|
||||
|
||||
def deliver(%Email{} = email, _) do
|
||||
email
|
||||
|> Map.put(:text_body, nil)
|
||||
|> Mailer.deliver([
|
||||
adapter: Swoosh.Adapters.SMTP,
|
||||
relay: "mail.mailinator.com",
|
||||
port: 25,
|
||||
tls: :never,
|
||||
auth: :never,
|
||||
retries: 1,
|
||||
no_mx_lookups: true
|
||||
])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
defmodule SwooshMailinator.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[
|
||||
version: "0.1.0",
|
||||
deps: [
|
||||
{:swoosh, "~> 1.7"},
|
||||
]
|
||||
]
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
%{
|
||||
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
|
||||
"mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"},
|
||||
"swoosh": {:hex, :swoosh, "1.16.9", "20c6a32ea49136a4c19f538e27739bb5070558c0fa76b8a95f4d5d5ca7d319a1", [:mix], [{:bandit, ">= 1.0.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mua, "~> 0.2.0", [hex: :mua, repo: "hexpm", optional: true]}, {:multipart, "~> 0.4", [hex: :multipart, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:req, "~> 0.5 or ~> 1.0", [hex: :req, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "878b1a7a6c10ebbf725a3349363f48f79c5e3d792eb621643b0d276a38acc0a6"},
|
||||
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
Mix.install(
|
||||
[
|
||||
{:swoosh, "~> 1.7"},
|
||||
{:gen_smtp, "~> 1.1"},
|
||||
{:hackney, "~> 1.8"},
|
||||
{:swoosh_mailinator, path: "."}, #app: false }
|
||||
]
|
||||
)
|
||||
|
||||
defmodule Main do
|
||||
import Swoosh.Email
|
||||
import Swoosh.Mailer
|
||||
|
||||
def main do
|
||||
mess = """
|
||||
Compose, deliver and test your emails easily in Elixir.
|
||||
|
||||
Swoosh comes with many adapters, including SendGrid, Mandrill, Mailgun, Postmark and SMTP. See the full list of adapters below.
|
||||
|
||||
The complete documentation for Swoosh is available online at HexDocs.
|
||||
"""
|
||||
new()
|
||||
|> to("mlkjhg@kiujygtrfedc.com")
|
||||
|> from({"Who Knows", "who.knows@nonexisting.tld"})
|
||||
|> subject("Hello, Swoosh!")
|
||||
|> html_body("<h1>Hello World</h1><p>"<>mess<>"</p>")
|
||||
|> text_body(mess)
|
||||
|> IO.inspect()
|
||||
|> deliver([
|
||||
adapter: Swoosh.Adapters.Mailinator
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
Main.main() |> IO.inspect()
|
Loading…
Reference in New Issue