can send emails on a whim
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
(ns auto-ap.db.reminders
|
||||
(:require [auto-ap.db.utils :refer [clj->db db->clj get-conn]]
|
||||
[clj-time.core :as time]
|
||||
[amazonica.aws.simpleemail :as ses]
|
||||
[clojure.java.jdbc :as j]
|
||||
[config.core :refer [env]]
|
||||
[clj-time.jdbc :as jdbc]
|
||||
[clojure.string :as str]))
|
||||
|
||||
@@ -34,9 +36,27 @@
|
||||
(defn get-ready []
|
||||
(map db->clj (j/query (get-conn)
|
||||
(str
|
||||
" SELECT reminders.*, vendors.name as vendor_name, vendors.email "
|
||||
" SELECT reminders.*, vendors.name as vendor_name "
|
||||
" FROM reminders INNER join vendors on reminders.vendor_id = vendors.id "
|
||||
" WHERE reminders.sent IS NULL AND reminders.scheduled < NOW()"))))
|
||||
|
||||
(defn finish [id]
|
||||
(j/update! (get-conn) :reminders {:sent (time/now)} ["id = ?" id] ))
|
||||
|
||||
(defn template []
|
||||
{:subject "Reminder to send invoices"
|
||||
:body (str "This is a reminder to please reply with a [format of invoice: pdf/excel]"
|
||||
"version of last week's invoices for:"
|
||||
"We would greatly appreciate it if you could send that to us by end of day on"
|
||||
"Monday.")})
|
||||
|
||||
(defn send-emails [reminders]
|
||||
(doseq [{:keys [vendor-name id email subject body]} reminders]
|
||||
(when email
|
||||
(println "Sending email to" email)
|
||||
(ses/send-email :destination {:to-addresses [email]}
|
||||
:source (:invoice-email env)
|
||||
:message {:subject subject
|
||||
:body {:html (str "<h1>Hello " vendor-name ",</h1><p>" body "</p> <p> - Integreat. </p>")
|
||||
:text (str "Hello " vendor-name ",\r\n" body "\r\n - Integreat.")}}))
|
||||
(finish id)))
|
||||
|
||||
Reference in New Issue
Block a user