mirror of
https://github.com/penpot/penpot.git
synced 2025-01-23 15:09:10 -05:00
♻️ Add smtp backend for sendmail task.
This commit is contained in:
parent
7fba483bf1
commit
428bd42f15
3 changed files with 48 additions and 12 deletions
|
@ -36,7 +36,6 @@
|
||||||
:sendmail-reply-to "no-reply@example.com"
|
:sendmail-reply-to "no-reply@example.com"
|
||||||
:sendmail-from "no-reply@example.com"
|
:sendmail-from "no-reply@example.com"
|
||||||
|
|
||||||
:smtp-enabled false
|
|
||||||
:allow-demo-users true
|
:allow-demo-users true
|
||||||
:registration-enabled true
|
:registration-enabled true
|
||||||
:registration-domain-whitelist ""
|
:registration-domain-whitelist ""
|
||||||
|
@ -64,7 +63,6 @@
|
||||||
(s/def ::smtp-password (s/nilable ::us/string))
|
(s/def ::smtp-password (s/nilable ::us/string))
|
||||||
(s/def ::smtp-tls ::us/boolean)
|
(s/def ::smtp-tls ::us/boolean)
|
||||||
(s/def ::smtp-ssl ::us/boolean)
|
(s/def ::smtp-ssl ::us/boolean)
|
||||||
(s/def ::smtp-enabled ::us/boolean)
|
|
||||||
(s/def ::allow-demo-users ::us/boolean)
|
(s/def ::allow-demo-users ::us/boolean)
|
||||||
(s/def ::registration-enabled ::us/boolean)
|
(s/def ::registration-enabled ::us/boolean)
|
||||||
(s/def ::registration-domain-whitelist ::us/string)
|
(s/def ::registration-domain-whitelist ::us/string)
|
||||||
|
@ -91,7 +89,6 @@
|
||||||
::smtp-password
|
::smtp-password
|
||||||
::smtp-tls
|
::smtp-tls
|
||||||
::smtp-ssl
|
::smtp-ssl
|
||||||
::smtp-enabled
|
|
||||||
::debug-humanize-transit
|
::debug-humanize-transit
|
||||||
::allow-demo-users
|
::allow-demo-users
|
||||||
::registration-enabled]))
|
::registration-enabled]))
|
||||||
|
|
|
@ -11,9 +11,13 @@
|
||||||
(:require
|
(:require
|
||||||
[clojure.data.json :as json]
|
[clojure.data.json :as json]
|
||||||
[clojure.tools.logging :as log]
|
[clojure.tools.logging :as log]
|
||||||
|
[postal.core :as postal]
|
||||||
[promesa.core :as p]
|
[promesa.core :as p]
|
||||||
|
[uxbox.common.data :as d]
|
||||||
|
[uxbox.common.exceptions :as ex]
|
||||||
[uxbox.config :as cfg]
|
[uxbox.config :as cfg]
|
||||||
[uxbox.util.http :as http]))
|
[uxbox.util.http :as http]
|
||||||
|
[vertx.util :as vu]))
|
||||||
|
|
||||||
(defmulti sendmail (fn [config email] (:sendmail-backend config)))
|
(defmulti sendmail (fn [config email] (:sendmail-backend config)))
|
||||||
|
|
||||||
|
@ -49,16 +53,48 @@
|
||||||
:headers headers
|
:headers headers
|
||||||
:uri "https://api.sendgrid.com/v3/mail/send"
|
:uri "https://api.sendgrid.com/v3/mail/send"
|
||||||
:body body})
|
:body body})
|
||||||
(p/handle (fn [response error]
|
(p/handle
|
||||||
(cond
|
(fn [response error]
|
||||||
error
|
(cond
|
||||||
(log/error "Error on sending email to sendgrid:" (pr-str error))
|
error
|
||||||
|
(log/error "Error on sending email to sendgrid:" (pr-str error))
|
||||||
|
|
||||||
(= 202 (:status response))
|
(= 202 (:status response))
|
||||||
nil
|
nil
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(log/error "Unexpected status from sendgrid:" (pr-str response))))))))
|
(log/error "Unexpected status from sendgrid:" (pr-str response))))))))
|
||||||
|
|
||||||
|
(defn- get-smtp-config
|
||||||
|
[config]
|
||||||
|
{:host (:smtp-host config)
|
||||||
|
:port (:smtp-port config)
|
||||||
|
:user (:smtp-user config)
|
||||||
|
:pass (:smtp-password config)
|
||||||
|
:ssl (:smtp-ssl config)
|
||||||
|
:tls (:smtp-tls config)})
|
||||||
|
|
||||||
|
(defn- email->postal
|
||||||
|
[email]
|
||||||
|
{:from (:from email)
|
||||||
|
:to (:to email)
|
||||||
|
:subject (:subject email)
|
||||||
|
:body (d/concat [:alternative]
|
||||||
|
(map (fn [{:keys [type value]}]
|
||||||
|
{:type (str type "; charset=utf-8")
|
||||||
|
:content value})
|
||||||
|
(:content email)))})
|
||||||
|
|
||||||
|
(defmethod sendmail "smtp"
|
||||||
|
[config email]
|
||||||
|
(vu/blocking
|
||||||
|
(let [config (get-smtp-config config)
|
||||||
|
email (email->postal email)
|
||||||
|
result (postal/send-message config email)]
|
||||||
|
(when (not= (:error result) :SUCCESS)
|
||||||
|
(ex/raise :type :sendmail-error
|
||||||
|
:code :email-not-sent
|
||||||
|
:context result)))))
|
||||||
|
|
||||||
(defn handler
|
(defn handler
|
||||||
{:uxbox.tasks/name "sendmail"}
|
{:uxbox.tasks/name "sendmail"}
|
||||||
|
|
|
@ -42,6 +42,9 @@ services:
|
||||||
- UXBOX_DATABASE_URI=postgresql://postgres/uxbox
|
- UXBOX_DATABASE_URI=postgresql://postgres/uxbox
|
||||||
- UXBOX_DATABASE_USERNAME=uxbox
|
- UXBOX_DATABASE_USERNAME=uxbox
|
||||||
- UXBOX_DATABASE_PASSWORD=uxbox
|
- UXBOX_DATABASE_PASSWORD=uxbox
|
||||||
|
- UXBOX_SENDMAIL_BACKEND=smtp
|
||||||
|
- UXBOX_SMTP_HOST=smtp
|
||||||
|
- UXBOX_SMTP_PORT=25
|
||||||
|
|
||||||
smtp:
|
smtp:
|
||||||
container_name: "uxbox-devenv-smtp"
|
container_name: "uxbox-devenv-smtp"
|
||||||
|
|
Loading…
Add table
Reference in a new issue