I recommend using the Apache Commons Email library when sending email from Clojure apps. Here’s a simple example.
First up, you need to add the dependency to ‘project.clj’
1 2 3 4 |
:dependencies [ [org.clojure/clojure "1.10.1"] [org.apache.commons/commons-email "1.5"] ] |
Next, your code would look something like the following. Caution, … This will send emails, so configure it to send the emails to a personal email address for testing purposes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
(ns email-example.core (:import (org.apache.commons.mail SimpleEmail))) (defn -main "I send plaintext emails using the Apache Commons Email library." [& args] (println "Email the World ...") ;; for more methods, such as for authentication, look at the manual... ;; http://commons.apache.org/proper/commons-email/userguide.html (let [smtp-address "smtp.example.com" subject "Test email" msg "This is your basic plain text email. Enjoy!"] (doto (SimpleEmail.) (.setHostName smtp-address) (.setFrom from) (.setSubject subject) (.setMsg msg) (.addTo to) (.send))) (println "... Email Sent!")) |