-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows us to ignore a testing account with an invalid email address.
- Loading branch information
Showing
2 changed files
with
29 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
;; A set of addresses that we never want to send an email to. | ||
#{ | ||
;; Used by GitHub on the account they use for integration testing token breach | ||
;; reporting, but it doesn't actually exist, resulting in monitoring noise | ||
"[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,41 @@ | ||
(ns clojars.email | ||
(:require | ||
[clojars.log :as log]) | ||
[clojars.log :as log] | ||
[clojure.edn :as edn] | ||
[clojure.java.io :as io]) | ||
(:import | ||
(java.util.concurrent | ||
CountDownLatch | ||
TimeUnit) | ||
(org.apache.commons.mail | ||
SimpleEmail))) | ||
|
||
(def ^:private email-denylist | ||
(edn/read-string (slurp (io/resource "email-denylist.edn")))) | ||
|
||
(defn simple-mailer [{:keys [hostname username password port tls? from]}] | ||
(fn [to subject message] | ||
(log/with-context {:tag :email | ||
:email-to to | ||
:email-subject subject} | ||
(try | ||
(let [mail (doto (SimpleEmail.) | ||
(.setHostName (or hostname "localhost")) | ||
(.setSmtpPort (or port 25)) | ||
(.setStartTLSEnabled (boolean tls?)) | ||
(.setStartTLSRequired (boolean tls?)) | ||
(.setFrom (or from "[email protected]") "Clojars") | ||
(.addTo to) | ||
(.setSubject subject) | ||
(.setMsg message))] | ||
(when tls? | ||
(.setSslSmtpPort mail (str (or port 25)))) | ||
(when (and username password) | ||
(.setAuthentication mail username password)) | ||
(.send mail) | ||
(log/info {:status :success})) | ||
(if (contains? email-denylist to) | ||
(log/info {:status :denylist}) | ||
(let [mail (doto (SimpleEmail.) | ||
(.setHostName (or hostname "localhost")) | ||
(.setSmtpPort (or port 25)) | ||
(.setStartTLSEnabled (boolean tls?)) | ||
(.setStartTLSRequired (boolean tls?)) | ||
(.setFrom (or from "[email protected]") "Clojars") | ||
(.addTo to) | ||
(.setSubject subject) | ||
(.setMsg message))] | ||
(when tls? | ||
(.setSslSmtpPort mail (str (or port 25)))) | ||
(when (and username password) | ||
(.setAuthentication mail username password)) | ||
(.send mail) | ||
(log/info {:status :success}))) | ||
(catch Exception e | ||
(log/error {:status :failed | ||
:error e}) | ||
|