Skip to content

Commit

Permalink
Add support for Protonmail Bridge (#739)
Browse files Browse the repository at this point in the history
* 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
Raphexion and princemaple committed Dec 26, 2022
1 parent 4345854 commit 0d59bdd
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 17 deletions.
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,24 @@ Swoosh supports the most popular transactional email providers out of the box
and also has a SMTP adapter. Below is the list of the adapters currently
included:

| Provider | Swoosh adapter |
| ---------- | ----------------------------------------------------------------------------------------------- |
| SMTP | [Swoosh.Adapters.SMTP](https://hexdocs.pm/swoosh/Swoosh.Adapters.SMTP.html#content) |
| SendGrid | [Swoosh.Adapters.Sendgrid](https://hexdocs.pm/swoosh/Swoosh.Adapters.Sendgrid.html#content) |
| Sendinblue | [Swoosh.Adapters.Sendinblue](https://hexdocs.pm/swoosh/Swoosh.Adapters.Sendinblue.html#content) |
| Sendmail | [Swoosh.Adapters.Sendmail](https://hexdocs.pm/swoosh/Swoosh.Adapters.Sendmail.html#content) |
| Mandrill | [Swoosh.Adapters.Mandrill](https://hexdocs.pm/swoosh/Swoosh.Adapters.Mandrill.html#content) |
| Mailgun | [Swoosh.Adapters.Mailgun](https://hexdocs.pm/swoosh/Swoosh.Adapters.Mailgun.html#content) |
| Mailjet | [Swoosh.Adapters.Mailjet](https://hexdocs.pm/swoosh/Swoosh.Adapters.Mailjet.html#content) |
| Postmark | [Swoosh.Adapters.Postmark](https://hexdocs.pm/swoosh/Swoosh.Adapters.Postmark.html#content) |
| SparkPost | [Swoosh.Adapters.SparkPost](https://hexdocs.pm/swoosh/Swoosh.Adapters.SparkPost.html#content) |
| Amazon SES | [Swoosh.Adapters.AmazonSES](https://hexdocs.pm/swoosh/Swoosh.Adapters.AmazonSES.html#content) |
| Dyn | [Swoosh.Adapters.Dyn](https://hexdocs.pm/swoosh/Swoosh.Adapters.Dyn.html#content) |
| SocketLabs | [Swoosh.Adapters.SocketLabs](https://hexdocs.pm/swoosh/Swoosh.Adapters.SocketLabs.html#content) |
| Gmail | [Swoosh.Adapters.Gmail](https://hexdocs.pm/swoosh/Swoosh.Adapters.Gmail.html#content) |
| MailPace | [Swoosh.Adapters.MailPace](https://hexdocs.pm/swoosh/Swoosh.Adapters.MailPace.html#content) |
| SMTP2GO | [Swoosh.Adapters.SMTP2GO](https://hexdocs.pm/swoosh/Swoosh.Adapters.SMTP2GO.html#content) |
| Provider | Swoosh adapter |
|--------------|-----------------------------------------------------------------------------------------------------|
| SMTP | [Swoosh.Adapters.SMTP](https://hexdocs.pm/swoosh/Swoosh.Adapters.SMTP.html#content) |
| SendGrid | [Swoosh.Adapters.Sendgrid](https://hexdocs.pm/swoosh/Swoosh.Adapters.Sendgrid.html#content) |
| Sendinblue | [Swoosh.Adapters.Sendinblue](https://hexdocs.pm/swoosh/Swoosh.Adapters.Sendinblue.html#content) |
| Sendmail | [Swoosh.Adapters.Sendmail](https://hexdocs.pm/swoosh/Swoosh.Adapters.Sendmail.html#content) |
| Mandrill | [Swoosh.Adapters.Mandrill](https://hexdocs.pm/swoosh/Swoosh.Adapters.Mandrill.html#content) |
| Mailgun | [Swoosh.Adapters.Mailgun](https://hexdocs.pm/swoosh/Swoosh.Adapters.Mailgun.html#content) |
| Mailjet | [Swoosh.Adapters.Mailjet](https://hexdocs.pm/swoosh/Swoosh.Adapters.Mailjet.html#content) |
| Postmark | [Swoosh.Adapters.Postmark](https://hexdocs.pm/swoosh/Swoosh.Adapters.Postmark.html#content) |
| SparkPost | [Swoosh.Adapters.SparkPost](https://hexdocs.pm/swoosh/Swoosh.Adapters.SparkPost.html#content) |
| Amazon SES | [Swoosh.Adapters.AmazonSES](https://hexdocs.pm/swoosh/Swoosh.Adapters.AmazonSES.html#content) |
| Dyn | [Swoosh.Adapters.Dyn](https://hexdocs.pm/swoosh/Swoosh.Adapters.Dyn.html#content) |
| SocketLabs | [Swoosh.Adapters.SocketLabs](https://hexdocs.pm/swoosh/Swoosh.Adapters.SocketLabs.html#content) |
| Gmail | [Swoosh.Adapters.Gmail](https://hexdocs.pm/swoosh/Swoosh.Adapters.Gmail.html#content) |
| MailPace | [Swoosh.Adapters.MailPace](https://hexdocs.pm/swoosh/Swoosh.Adapters.MailPace.html#content) |
| SMTP2GO | [Swoosh.Adapters.SMTP2GO](https://hexdocs.pm/swoosh/Swoosh.Adapters.SMTP2GO.html#content) |
| ProtonBridge | [Swoosh.Adapters.ProtonBridge](https://hexdocs.pm/swoosh/Swoosh.Adapters.ProtonBridge.html#content) |

Configure which adapter you want to use by updating your `config/config.exs`
file:
Expand Down
54 changes: 54 additions & 0 deletions lib/swoosh/adapters/proton_bridge.ex
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

0 comments on commit 0d59bdd

Please sign in to comment.