I’m trying to send email from Clojure using the following code:
Helper function that sends email:
(defn- send [recipient from subject msg host content-type & attachments]
(let [att-ds (map (fn [at] {:ds (ByteArrayDataSource. (:source at)
(:type at))
:name (:name at)
:description (:description at)})
attachments)
mpmail (MultiPartEmail.)]
(doto mpmail
(.setHostName host)
(.setFrom from)
(.setSubject subject)
(.setContent msg content-type)
(.setCharset "utf-8"))
(.addTo mpmail recipient)
(doseq [ds att-ds]
(.attach mpmail (:ds ds) (:name ds) (:description ds)))
(.send mpmail)))
Usage:
(send "sender@my.domain"
"recipient@my.domain"
"SUBJECT"
"MSG"
"my.smtp.server"
"text/plain"
{:source (.getBytes "Attachment")
:type "text/plain"
:name "test.txt"
:description "test"})
Running the above from the REPL (or from my app) results in recipient@my.domain receiving an email with the subject “SUBJECT” and body “MSG” but without any traces of attachment. No exceptions are raised anywhere.
I have tried this with two different smtp servers.
Thanks for any help.
Try replace
(.setContent msg)with(.setMsg msg). May be when you callsetContentit thinks you manually set content and ignores followingattachmethods.