Improve email console logging

And invitation console logging
This commit is contained in:
Andrey Antukh 2022-04-06 09:40:20 +02:00
parent 39fa939f58
commit fd9b442075
2 changed files with 22 additions and 11 deletions

View file

@ -8,6 +8,7 @@
"Main api for send emails." "Main api for send emails."
(:require (:require
[app.common.logging :as l] [app.common.logging :as l]
[app.common.pprint :as pp]
[app.common.spec :as us] [app.common.spec :as us]
[app.config :as cf] [app.config :as cf]
[app.db :as db] [app.db :as db]
@ -165,19 +166,25 @@
(let [enabled? (or (contains? cf/flags :smtp) (let [enabled? (or (contains? cf/flags :smtp)
(cf/get :smtp-enabled) (cf/get :smtp-enabled)
(:enabled task))] (:enabled task))]
(if enabled? (when enabled?
(emails/send! cfg props) (emails/send! cfg props))
(when (contains? cf/flags :log-emails)
(send-console! cfg props))))) (send-console! cfg props)))))
(defn- send-console! (defn- send-console!
[cfg email] [cfg email]
(let [baos (java.io.ByteArrayOutputStream.) (let [body (:body email)
mesg (emails/smtp-message cfg email)] out (with-out-str
(.writeTo mesg baos) (println "email console dump:")
(let [out (with-out-str (println "******** start email" (:id email) "**********")
(println "email console dump:") (pp/pprint (dissoc email :body))
(println "******** start email" (:id email) "**********") (if (string? body)
(println (.toString baos)) (println body)
(println "******** end email "(:id email) "**********"))] (println (->> body
(l/info :email out)))) (filter #(= "text/plain" (:type %)))
(map :content)
first)))
(println "******** end email" (:id email) "**********"))]
(l/info ::l/raw out)))

View file

@ -8,6 +8,7 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.logging :as l]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.config :as cf] [app.config :as cf]
@ -412,6 +413,9 @@
{:iss :profile-identity {:iss :profile-identity
:profile-id (:id profile)})] :profile-id (:id profile)})]
(when (contains? cf/flags :log-invitation-tokens)
(l/trace :hint "invitation token" :token itoken))
(when (and member (not (eml/allow-send-emails? conn member))) (when (and member (not (eml/allow-send-emails? conn member)))
(ex/raise :type :validation (ex/raise :type :validation
:code :member-is-muted :code :member-is-muted