diff --git a/config/dev.edn b/config/dev.edn index cc799234..55ec6f71 100644 --- a/config/dev.edn +++ b/config/dev.edn @@ -8,6 +8,7 @@ :invoice-import-queue-url "https://sqs.us-east-1.amazonaws.com/679918342773/integreat-mail-staging" :requests-queue-url "https://sqs.us-east-1.amazonaws.com/679918342773/integreat-background-request-prod" :invoice-email "invoices-staging@mail.app.integreatconsult.com" + :import-failure-destination-email "bryce@brycecovertoperations.com" :data-bucket "data.staging.app.integreatconsult.com" :plaid {:base-url "https://sandbox.plaid.com" :client-id "61bfab05f7e762001b323f79" diff --git a/config/prod-background-worker.edn b/config/prod-background-worker.edn index e4cd8584..550e6545 100644 --- a/config/prod-background-worker.edn +++ b/config/prod-background-worker.edn @@ -7,6 +7,7 @@ :invoice-import-queue-url "https://sqs.us-east-1.amazonaws.com/679918342773/integreat-mail-prod" :requests-queue-url "https://sqs.us-east-1.amazonaws.com/679918342773/integreat-background-request-prod" :invoice-email "invoices@mail.app.integreatconsult.com" + :import-failure-destination-email "ben@integreatconsult.com" :data-bucket "data.prod.app.integreatconsult.com" :yodlee-cobrand-name "qstartus12" :yodlee-cobrand-login "qstartus12" diff --git a/config/prod.edn b/config/prod.edn index 901037a3..c3b331e8 100644 --- a/config/prod.edn +++ b/config/prod.edn @@ -7,6 +7,7 @@ :invoice-import-queue-url "https://sqs.us-east-1.amazonaws.com/679918342773/integreat-mail-prod" :requests-queue-url "https://sqs.us-east-1.amazonaws.com/679918342773/integreat-background-request-prod" :invoice-email "invoices@mail.app.integreatconsult.com" + :import-failure-destination-email "ben@integreatconsult.com" :data-bucket "data.prod.app.integreatconsult.com" :yodlee-cobrand-name "qstartus12" :yodlee-cobrand-login "qstartus12" diff --git a/config/staging.edn b/config/staging.edn index 96be3e7b..0c77e289 100644 --- a/config/staging.edn +++ b/config/staging.edn @@ -7,6 +7,8 @@ :invoice-import-queue-url "https://sqs.us-east-1.amazonaws.com/679918342773/integreat-mail-staging" :requests-queue-url "https://sqs.us-east-1.amazonaws.com/679918342773/integreat-background-request-staging" :invoice-email "invoices-staging@mail.app.integreatconsult.com" + + :import-failure-destination-email "bryce@brycecovertoperations.com" :data-bucket "data.staging.app.integreatconsult.com" :yodlee-cobrand-name "qstartus12" :yodlee-cobrand-login "qstartus12" diff --git a/project.clj b/project.clj index 0d60b875..f757b55f 100644 --- a/project.clj +++ b/project.clj @@ -66,15 +66,15 @@ [com.amazonaws/aws-java-sdk-core "1.11.926" :exclusions [commons-codec commons-logging]] - [com.amazonaws/aws-java-sdk-ses "1.11.926" - :exclusions [commons-codec - org.apache.httpcomponents/httpclient]] [com.amazonaws/aws-java-sdk-s3 "1.11.926" :exclusions [commons-codec org.apache.httpcomponents/httpclient]] [com.amazonaws/aws-java-sdk-sqs "1.11.926" :exclusions [commons-codec org.apache.httpcomponents/httpclient]] + [com.amazonaws/aws-java-sdk-ses "1.11.926" + :exclusions [commons-codec + org.apache.httpcomponents/httpclient]] [com.amazonaws/aws-java-sdk-dynamodb "1.11.926" :exclusions [commons-codec org.apache.httpcomponents/httpclient]] diff --git a/src/clj/auto_ap/background/mail.clj b/src/clj/auto_ap/background/mail.clj index ce228e02..3ee9d75d 100644 --- a/src/clj/auto_ap/background/mail.clj +++ b/src/clj/auto_ap/background/mail.clj @@ -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 "
You can download the original email here.
") + :text (str "
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) )))