|
1 | 1 | (ns clojars.email |
2 | 2 | (:require |
3 | | - [clojars.log :as log]) |
| 3 | + [clojars.log :as log] |
| 4 | + [clojure.edn :as edn] |
| 5 | + [clojure.java.io :as io]) |
4 | 6 | (:import |
5 | 7 | (java.util.concurrent |
6 | 8 | CountDownLatch |
7 | 9 | TimeUnit) |
8 | 10 | (org.apache.commons.mail |
9 | 11 | SimpleEmail))) |
10 | 12 |
|
| 13 | +(def ^:private email-denylist |
| 14 | + (edn/read-string (slurp (io/resource "email-denylist.edn")))) |
| 15 | + |
11 | 16 | (defn simple-mailer [{:keys [hostname username password port tls? from]}] |
12 | 17 | (fn [to subject message] |
13 | 18 | (log/with-context {:tag :email |
14 | 19 | :email-to to |
15 | 20 | :email-subject subject} |
16 | 21 | (try |
17 | | - (let [mail (doto (SimpleEmail.) |
18 | | - (.setHostName (or hostname "localhost")) |
19 | | - (.setSmtpPort (or port 25)) |
20 | | - (.setStartTLSEnabled (boolean tls?)) |
21 | | - (.setStartTLSRequired (boolean tls?)) |
22 | | - (.setFrom (or from "contact@clojars.org") "Clojars") |
23 | | - (.addTo to) |
24 | | - (.setSubject subject) |
25 | | - (.setMsg message))] |
26 | | - (when tls? |
27 | | - (.setSslSmtpPort mail (str (or port 25)))) |
28 | | - (when (and username password) |
29 | | - (.setAuthentication mail username password)) |
30 | | - (.send mail) |
31 | | - (log/info {:status :success})) |
| 22 | + (if (contains? email-denylist to) |
| 23 | + (log/info {:status :denylist}) |
| 24 | + (let [mail (doto (SimpleEmail.) |
| 25 | + (.setHostName (or hostname "localhost")) |
| 26 | + (.setSmtpPort (or port 25)) |
| 27 | + (.setStartTLSEnabled (boolean tls?)) |
| 28 | + (.setStartTLSRequired (boolean tls?)) |
| 29 | + (.setFrom (or from "contact@clojars.org") "Clojars") |
| 30 | + (.addTo to) |
| 31 | + (.setSubject subject) |
| 32 | + (.setMsg message))] |
| 33 | + (when tls? |
| 34 | + (.setSslSmtpPort mail (str (or port 25)))) |
| 35 | + (when (and username password) |
| 36 | + (.setAuthentication mail username password)) |
| 37 | + (.send mail) |
| 38 | + (log/info {:status :success}))) |
32 | 39 | (catch Exception e |
33 | 40 | (log/error {:status :failed |
34 | 41 | :error e}) |
|
0 commit comments