testing system sending automated emails.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
(ns auto-ap.background.mail
|
||||
(:require [amazonica.aws.s3 :as s3]
|
||||
[amazonica.aws.sqs :as sqs]
|
||||
[amazonica.aws.simpleemail :as ses]
|
||||
[auto-ap.parse :as parse]
|
||||
[auto-ap.routes.invoices :as invoices]
|
||||
[clojure-mail.message :as message]
|
||||
@@ -17,6 +18,19 @@
|
||||
(javax.mail.internet MimeMessage)))
|
||||
|
||||
|
||||
(defn send-email-about-failed-message [mail-bucket mail-key]
|
||||
(let [target-key (str "failed-emails/" mail-key ".eml")
|
||||
target-url (str "http://" (:data-bucket env)
|
||||
".s3-website-us-east-1.amazonaws.com/"
|
||||
target-key)]
|
||||
(s3/copy-object mail-bucket mail-key (:data-bucket env) target-key)
|
||||
(ses/send-email {:destination {:to-addresses [(:import-failure-destination-email env)]}
|
||||
:source (:invoice-email env)
|
||||
:message {:subject "An email invoice import failed"
|
||||
:body {:html (str "<div>You can download the original email <a href=\"" target-url "\">here</a>.</div>")
|
||||
:text (str "<div>You can download the original email here: " target-url)}}})))
|
||||
|
||||
|
||||
(defn process-sqs []
|
||||
(lc/with-context {:source "import-uploaded-invoices"}
|
||||
(try
|
||||
@@ -56,7 +70,8 @@
|
||||
(log/info "Found imports" imports)
|
||||
(invoices/import-uploaded-invoice {:user/role "admin"} imports ))
|
||||
(catch Exception e
|
||||
(log/warn e))
|
||||
(log/warn e)
|
||||
(send-email-about-failed-message (-> r :s3 :bucket :name) (-> r :s3 :object :key)))
|
||||
(finally
|
||||
(io/delete-file filename)))))))
|
||||
(sqs/delete-message (assoc message :queue-url (:invoice-import-queue-url env) )))
|
||||
|
||||
Reference in New Issue
Block a user