Liking cljdoc? Tell your friends :D

tarayo

SMTP client library for Clojure. That’s it.

This project is under development.

Why tarayo?

Tarayo is heavily inspired by drewr/postal.

  • Only targets SMTP

  • Explicit connection

    • Handle the connection manually.

  • Well tested

"Tarayo" is a tree name called "Tree of post office" in Japan.

Usage

tarayo

(ns foo.core
  (:require [tarayo.core :as tarayo]))

Connection SMTP server

tarayo.core/connect is a function to connect SMTP server.
You need to call tarayo.core/close function before quitting, or use with-open macro.

(with-open [conn (tarayo/connect {:host "localhost" :port 25})]
  ;; send mails
  )

Other examples are follows:

SSL connection

(tarayo/connect {:host "localhost" :port 465 :ssl true})

TLS connection

(tarayo/connect {:host "localhost" :port 587 :tls true})

Connection with user authentication

(tarayo/connect {:host "localhost" :port 25 :user "USERNAME" :password "PASSWORD"})

Sending mails

Text mail

(with-open [conn (tarayo/connect {:host "localhost" :port 25})]
  (tarayo/send! conn {:from "alice@example.com"
                      :to "bob@example.com"
                      :subject "hello"
                      :body "world"}))

HTML mail

(with-open [conn (tarayo/connect {:host "localhost" :port 25})]
  (tarayo/send! conn {:from "alice@example.com"
                      :to "bob@example.com"
                      :subject "hello"
                      :content-type "text/html
                      :body "<h1>world</h1>"}))

Attachment file

(require '[clojure.java.io :as io])

(with-open [conn (tarayo/connect {:host "localhost" :port 25})]
  (tarayo/send! conn {:from "alice@example.com"
                      :to "bob@example.com"
                      :subject "hello"
                      ;; Default multipart type is "mixed"
                      :body [{:type "text/plain" :content "world"}
                             ;; content-type is automatically detected
                             {:type "attachment" :content (io/file "/file")}
                             {:type "attachment" :content (io/file "/image.png") :content-type "image/png"}]}))

Multipart/alternative

(with-open [conn (tarayo/connect {:host "localhost" :port 25})]
  (tarayo/send! conn {:from "alice@example.com"
                      :to "bob@example.com"
                      :subject "hello"
                      :multipart "alternative"
                      :body [{:type "text/plain" :content "world"}
                             {:type "text/html" :content "<h1>wold</h1>"}]}))

Inline image

(require '[clojure.java.io :as io])

(with-open [conn (tarayo/connect {:host "localhost" :port 25})]
  (let [content-id (java.util.UUID/randomUUID)]
    (tarayo/send! conn {:from "alice@example.com"
                        :to "bob@example.com"
                        :subject "hello"
                        :body [{:type "text/html" :content (str "<img src=\"cid:" content-id "\" /> world")}
                               {:type "inline" :content (io/file "/image.png") :id content-id}]})))

License

Copyright © 2019 Masashi Iizuka

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close