Skip to content

Commit 0d33a46

Browse files
committed
Add denylist for sending emails
This allows us to ignore a testing account with an invalid email address.
1 parent 3328761 commit 0d33a46

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

resources/email-denylist.edn

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
;; A set of addresses that we never want to send an email to.
2+
#{
3+
;; Used by GitHub on the account they use for integration testing token breach
4+
;; reporting, but it doesn't actually exist, resulting in monitoring noise
5+
"secret-scanning@gmail.com"
6+
}

src/clojars/email.clj

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
(ns clojars.email
22
(:require
3-
[clojars.log :as log])
3+
[clojars.log :as log]
4+
[clojure.edn :as edn]
5+
[clojure.java.io :as io])
46
(:import
57
(java.util.concurrent
68
CountDownLatch
79
TimeUnit)
810
(org.apache.commons.mail
911
SimpleEmail)))
1012

13+
(def ^:private email-denylist
14+
(edn/read-string (slurp (io/resource "email-denylist.edn"))))
15+
1116
(defn simple-mailer [{:keys [hostname username password port tls? from]}]
1217
(fn [to subject message]
1318
(log/with-context {:tag :email
1419
:email-to to
1520
:email-subject subject}
1621
(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})))
3239
(catch Exception e
3340
(log/error {:status :failed
3441
:error e})

0 commit comments

Comments
 (0)