drewr / postal

Clojure email support.

This URL has Read+Write access

drewr (author)
Fri Sep 11 12:54:44 -0700 2009
commit  bcbeb7488541a78aca012f6ebae43d6a5a17171f
tree    b5104ec67a776e41f159c9072dd9a5461a073523
parent  efb1ba85401a68ad960d247368d6a77416539e0b
postal /
name age message
file .gitignore Sun Jul 26 17:44:32 -0700 2009 Switch build to use ant/ivy. [drewr]
file LICENSE Mon Apr 20 16:40:18 -0700 2009 Add MIT license. [drewr]
file Makefile Mon Apr 20 16:26:55 -0700 2009 Add compilation and jar creation. [drewr]
file README.markdown Sun Jul 26 17:50:14 -0700 2009 Still mention JavaMail. [drewr]
directory bin/ Sun Jul 26 17:51:35 -0700 2009 Remove legacy build machinery. [drewr]
file build.xml Tue Aug 04 11:03:20 -0700 2009 Split ivy config into Java 1.5 and 1.6 versions... [drewr]
file ivy.xml Tue Aug 04 11:03:20 -0700 2009 Split ivy config into Java 1.5 and 1.6 versions... [drewr]
file ivysettings.xml Fri Sep 11 12:54:44 -0700 2009 Add ivy.draines repo. [drewr]
directory src/ Thu Sep 10 15:35:22 -0700 2009 Sanitize line endings when using sendmail. [drewr]
README.markdown

Postal

Internet email library for Clojure

Postal is a library for constructing and sending RFC822-compliant Internet email messages. It wraps the JavaMail package for message and SMTP support. It supports sendmail natively.

Platforms

  • Any Unix platform that supports Java and sendmail (msmtp, et al.)
  • Untested on Windows

Dependencies

  • JavaMail 1.4.2 (in lib/ after build)

Examples

At a bare minimum, provide a map with :from, :to, :subject, and :body. This will locally inject the message into sendmail.

user> (in-ns 'com.draines.postal.core)
#<Namespace com.draines.postal.core>
com.draines.postal.core> (send-message {:from "me@draines.com"
                                        :to ["mom@example.com" "dad@example.com"]
                                        :cc "bob@example.com"
                                        :subject "Hi!"
                                        :body "Test."})
{:code 0, :error :SUCCESS, :message "message sent"}
com.draines.postal.core> 

To use SMTP, add metadata with a :host key.

com.draines.postal.core> (send-message #^{:host "mail.isp.net"}
                                       {:from "me@draines.com"
                                        :to "foo@example.com"
                                        :subject "Hi!"
                                        :body "Test."})
{:code 0, :error :SUCCESS, :message "message sent"}
com.draines.postal.core> 

Attachments and multipart messages can be added as sequences of maps:

com.draines.postal.core> (send-message #^{:host "mail.isp.net"}
                                       {:from "me@draines.com"
                                        :to "foo@example.com"
                                        :subject "Hi!"
                                        :body [{:type "text/html"
                                                :content "<b>Test!</b>"}
                                            ;;;; supports both dispositions:
                                               {:type :attachment
                                                :content (java.io.File. "/tmp/foo.txt")}
                                               {:type :inline
                                                :content (java.io.File. "/tmp/foo.txt")}]})
{:code 0, :error :SUCCESS, :message "message sent"}
com.draines.postal.core>

Building

% ant dist
% ls dist
postal-20090726194310+32b4b1f.jar

License

Postal is (c) 2009 Drew Raines and released under the MIT license.