diff --git a/config.yaml b/config.yaml index 2c60228..deb69d8 100644 --- a/config.yaml +++ b/config.yaml @@ -1,3 +1,9 @@ domain: "http://localhost" debug: true port: 7404 +from: "api2smtp " +smtp-host: localhost +smtp-user: +smtp-pass: +smtp-ssl: false +smtp-port: 1025 diff --git a/resources/templates/emails/contact.html b/resources/templates/emails/contact.html new file mode 100644 index 0000000..4809f22 --- /dev/null +++ b/resources/templates/emails/contact.html @@ -0,0 +1,32 @@ +{% extends "layouts/base.html" %} + +{% block subject %} +{{ subject }} +{% endblock %} + +{% block content %} +

+ Name: +

+

+ {{ name }} +

+

+ Email: +

+

+ {{ email }} +

+

+ Subject: +

+

+ {{ subject }} +

+

+ Message: +

+

+ {{ message }} +

+{% endblock %} diff --git a/resources/templates/emails/contact.txt b/resources/templates/emails/contact.txt new file mode 100644 index 0000000..7016f15 --- /dev/null +++ b/resources/templates/emails/contact.txt @@ -0,0 +1,7 @@ +Name: {{ name }} + +Email: {{ email }} + +Subject: {{ subject }} + +Message: {{ message }} diff --git a/resources/templates/layouts/base.html b/resources/templates/layouts/base.html index 4c2c462..06ca788 100644 --- a/resources/templates/layouts/base.html +++ b/resources/templates/layouts/base.html @@ -1,29 +1,380 @@ - - - - - - - - {% block title %}{% endblock %} | Tadam Framework - - -
- - brand - - -
-
- {% block content %}{% endblock %} -
- - + + + + + {% block subject %}{% endblock %} + + + + + + + + + + + diff --git a/resources/templates/public/404.html b/resources/templates/public/404.html deleted file mode 100644 index 3c7952a..0000000 --- a/resources/templates/public/404.html +++ /dev/null @@ -1,9 +0,0 @@ -{% extends "layouts/base.html" %} - -{% block title %} -404 -{% endblock %} - -{% block content %} -

404

-{% endblock %} diff --git a/resources/templates/public/welcome.html b/resources/templates/public/welcome.html deleted file mode 100644 index aeb4490..0000000 --- a/resources/templates/public/welcome.html +++ /dev/null @@ -1,12 +0,0 @@ -{% extends "layouts/base.html" %} - -{% block title %} -Welcome to Tadam -{% endblock %} - -{% block content %} -

Welcome to Tadam Framework

-

- rabbit -

-{% endblock %} diff --git a/src/api2smtp/urls.clj b/src/api2smtp/urls.clj index 1c7b82d..f2daf5d 100644 --- a/src/api2smtp/urls.clj +++ b/src/api2smtp/urls.clj @@ -5,14 +5,14 @@ [api2smtp.views.public :as view-public])) (defroutes public - ;; Urls public pages - (POST "/api/v1/email/" [] view-public/index)) + ;; Urls public endpoints + (POST "/api/v1/email/" [] view-public/send)) (defroutes resources-routes ;; Resources (statics) (route/resources "/") - (route/not-found view-public/page-404)) + (route/not-found view-public/error)) (def all-routes ;; Wrap routers. "resources-routes" should always be the last. diff --git a/src/api2smtp/views/public.clj b/src/api2smtp/views/public.clj index 8bf5457..4079aba 100644 --- a/src/api2smtp/views/public.clj +++ b/src/api2smtp/views/public.clj @@ -1,20 +1,26 @@ ;;;; Views public web (ns api2smtp.views.public (:require - [tadam.templates :refer [render-JSON]] - [tadam.responses :refer [response]])) + [tadam.templates :refer [render-template render-JSON]] + [tadam.responses :refer [response]] + [tadam.email :refer [send]])) -(defn index - ;; View HTML +(defn send + ;; View Send email [req] - (let [name (-> :params :name) - subject (-> :params :subject) - email (-> :params :email) - message (-> :params :message)] + (let [params {:name (-> req :params :name) + :subject (-> req :params :subject) + :email (-> req :params :email) + :message (-> req :params :message)}] + ;; Send email + (send "to@email.com" "Contact" (render-template "emails/contact.html" params) (render-template "emails/contact.txt" params)) + ;; Response OK (render-JSON req {:status "ok"}))) -(defn page-404 +(defn error ;; View page 404 [req] + + ;; Response ERROR (response req "{\"status\": \"error\"}" 500 "text/json;charset=utf-8"))