summaryrefslogtreecommitdiff
path: root/src/email.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/email.clj')
-rw-r--r--src/email.clj35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/email.clj b/src/email.clj
index 2a68e7b..2fd22e1 100644
--- a/src/email.clj
+++ b/src/email.clj
@@ -1,6 +1,6 @@
(ns email
(:import org.antlr.stringtemplate.StringTemplateGroup)
- (:require [clojure.contrib.str-utils2 :as str-utils2]))
+ (:require [clojure.contrib.str-utils2 :as s]))
(defn base-mail [& m]
(let [mail (apply hash-map m)
@@ -34,10 +34,10 @@
(javax.mail.Message$RecipientType/TO)
(javax.mail.internet.InternetAddress/parse to)))
(.setSubject msg (:subject mail))
- (.setText msg (:text mail))
+ (.setContent msg (:text mail) (:mime mail))
(javax.mail.Transport/send msg))))
-(def mail-templates (new StringTemplateGroup "dumpfm-mail" "template/mail"))
+(def mail-templates (StringTemplateGroup. "dumpfm-mail" "template/mail" ))
(.setRefreshInterval mail-templates 3)
(defn parse-mail-template [temp props]
@@ -48,19 +48,28 @@
[(.trim (.replaceFirst s "SUBJECT: " ""))
(.trim b)])))
+(defn classify-mimetype [text]
+ (if (and (re-find #"(?i)<html>" text)
+ (re-find #"(?i)</html>" text))
+ "text/html"
+ "text/plain"))
+
(defn dump-mail [to subject text]
(base-mail :user "info@dump.fm"
- :password "dumprulez7"
- :host "smtpout.secureserver.net"
- :port 25
- :ssl false
- :to to
- :subject subject
- :text text))
+ :password "dumprulez7"
+ :host "smtpout.secureserver.net"
+ :port 25
+ :ssl false
+ :to to
+ :subject subject
+ :text text
+ :mime (classify-mimetype text)))
-(defn send-registration-email [nick email]
- (let [[s b] (parse-mail-template "welcome" {"nick" nick})]
- (dump-mail [email] s b)))
+(defn send-registration-email
+ ([nick email] (send-registration-email nick email "welcome"))
+ ([nick email temp]
+ (let [[s b] (parse-mail-template temp {"nick" nick})]
+ (dump-mail [email] s b))))
(defn send-reset-email [nick email key]
(let [[s b] (parse-mail-template "reset" {"nick" nick "key" key})]