Created
April 26, 2009 05:06
-
-
Save talios/101889 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns tip-smtp) | |
(defn morph-javamail-session | |
"Lookup the javamail session provided by mor.ph" | |
[] | |
(.lookup (javax.naming.InitialContext.) "java:/comp/env/mail/Session")) | |
(defn sendmail [& optlist] | |
"Send an email" | |
(let [opts (apply hash-map optlist)] | |
(let [msg (javax.mail.internet.MimeMessage. (morph-javamail-session))] | |
(cond (opts :text) (. msg (setText (opts :text))) | |
:else (. msg (setText (opts :html) "UTF-8" "html"))) | |
(.setSubject msg (opts :subject)) | |
(.setFrom msg ((javax.mail.internet.InternetAddress. (opts :user)))) | |
(doseq [rcpt (opts :to)] | |
(.addRecipient msg | |
javax.mail.Message$RecipientType/TO (javax.mail.internet.InternetAddress. rcpt))) | |
(javax.mail.Transport/send msg)))) | |
(sendmail | |
:user "Sender <someone@there>" | |
:to ["Mark Derricutt <me@here>"] | |
:subject "Test from mor.ph" | |
:text "This is a test message") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment