From e8b410012a856f6d7e2c402388b44e454b8c6449 Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Thu, 11 Jun 2020 17:38:47 +0200 Subject: [PATCH] Fixbug --- .gitignore | 1 + config.yaml | 2 +- project.clj | 2 +- src/api2smtp/urls.clj | 2 +- src/api2smtp/views/public.clj | 17 ++++++++++------- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 2f7896d..cc2c59b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ target/ +.lein-failures diff --git a/config.yaml b/config.yaml index deb69d8..07bde1d 100644 --- a/config.yaml +++ b/config.yaml @@ -1,7 +1,7 @@ domain: "http://localhost" debug: true port: 7404 -from: "api2smtp " +smtp-from: "api2smtp " smtp-host: localhost smtp-user: smtp-pass: diff --git a/project.clj b/project.clj index fa48e05..ce5736d 100644 --- a/project.clj +++ b/project.clj @@ -6,7 +6,7 @@ :dependencies [;; Clojure [org.clojure/clojure "1.10.1"] ;; Tadam core - [tadam-core "0.3.2"] + [tadam-core "0.4.0"] ;; HTTP Server [ring "1.8.0"] ;; Ring middleware that prevents CSRF attacks diff --git a/src/api2smtp/urls.clj b/src/api2smtp/urls.clj index f2daf5d..56ca96b 100644 --- a/src/api2smtp/urls.clj +++ b/src/api2smtp/urls.clj @@ -6,7 +6,7 @@ (defroutes public ;; Urls public endpoints - (POST "/api/v1/email/" [] view-public/send)) + (POST "/api/v1/email/" [] view-public/send-email)) (defroutes resources-routes diff --git a/src/api2smtp/views/public.clj b/src/api2smtp/views/public.clj index 4079aba..a6cde76 100644 --- a/src/api2smtp/views/public.clj +++ b/src/api2smtp/views/public.clj @@ -3,17 +3,20 @@ (:require [tadam.templates :refer [render-template render-JSON]] [tadam.responses :refer [response]] - [tadam.email :refer [send]])) + [tadam.utils :refer [get-JSON]] + [tadam.email :refer [send]] + [api2smtp.config :refer [config]])) -(defn send +(defn send-email ;; View Send email [req] - (let [params {:name (-> req :params :name) - :subject (-> req :params :subject) - :email (-> req :params :email) - :message (-> req :params :message)}] + (let [json (get-JSON req) + params {:name (-> json :name) + :subject (-> json :subject) + :email (-> json :email) + :message (-> json :message)}] ;; Send email - (send "to@email.com" "Contact" (render-template "emails/contact.html" params) (render-template "emails/contact.txt" params)) + (send config "to@email.com" "Contact" (render-template "emails/contact.html" params) (render-template "emails/contact.txt" params)) ;; Response OK (render-JSON req {:status "ok"})))