 
 (defn- send-postal [to-addresses cc-addresses bcc-addresses subject body content-type]
   (send-message
-   (select-keys mail-config [:host :user :pass :tls :port])
-   {:from    (:user mail-config)
+   (select-keys (get-config :mail) [:host :user :pass :tls :port])
+   {:from    (get-config :mail :user)
     :to      to-addresses
     :cc      cc-addresses
     :bcc     bcc-addresses

(ns collect-earth-online.utils.mail
  (:require [clojure.edn :as edn]
            [postal.core :refer [send-message]]
            [triangulum.config :refer [get-config]]
            [collect-earth-online.logging :refer [log-str]]))

;; Example value:
;; {:host                  "smtp.gmail.com"
;;  :user                  "mail@gmail.com"
;;  :pass                  "mail"
;;  :tls                   true
;;  :port                  587
;;  :base-url              "https://collect.earth/"
;;  :recipient-limit       100}
(defonce mail-config (get-config :mail))

(defn get-base-url []
  (:base-url mail-config))

(defn email? [string]
  (let [pattern #"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"]

                                             body
                                             content-type)]
    (when-not (= :SUCCESS error) (log-str message))))
