-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Protonmail Bridge (#739)
* Add support for Protonmail Bridge The Protonmail bridge is a local SMTP server that bridge to Protonmail. This adapter is a thin layer on-top the existing SMTP adapter. Even if this adapter is trivial, I hope people will find it useful. * Update proton_bridge.ex * Update proton_bridge.ex Co-authored-by: Po Chen <chenpaul914@gmail.com>
- Loading branch information
1 parent
4345854
commit 0d59bdd
Showing
2 changed files
with
72 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
defmodule Swoosh.Adapters.ProtonBridge do | ||
@moduledoc ~S""" | ||
An adapter that sends email using the local Protonmail Bridge. | ||
This is a very thin wrapper around the SMTP adapter. | ||
Underneath this adapter uses the | ||
[gen_smtp](https://github.com/Vagabond/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.ProtonBridge, | ||
username: "tonystark", | ||
password: "ilovepepperpotts", | ||
# lib/sample/mailer.ex | ||
defmodule Sample.Mailer do | ||
use Swoosh.Mailer, otp_app: :sample | ||
end | ||
""" | ||
|
||
use Swoosh.Adapter, required_config: [], required_deps: [gen_smtp: :gen_smtp_client] | ||
|
||
alias Swoosh.Email | ||
alias Swoosh.Adapters.SMTP | ||
|
||
@impl true | ||
def deliver(%Email{} = email, user_config) do | ||
config = Keyword.merge(bridge_config(), user_config) | ||
SMTP.deliver(email, config) | ||
end | ||
|
||
defp bridge_config do | ||
[ | ||
relay: "127.0.0.1", | ||
ssl: false, | ||
tls: :never, | ||
auth: :always, | ||
port: 1025, | ||
retries: 2, | ||
no_mx_lookups: true | ||
] | ||
end | ||
end |