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.enable true})

TLS connection

(tarayo/connect {:host "localhost" :port 587 :starttls.enable 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 [;; string content will be handled as "text message" while others are handled as "attachment file"
                             {:content "world"}
                             ;; If you don't specify `:content-type`, tarayo will detect it using Apache Tika automatically.
                             {:content (io/file "/file")}
                             ;; Of cource, you can specify `:content-type` manually.
                             {: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 [{:content-type "text/plain" :content "world"}
                             {:content-type "text/html" :content "<h1>wold</h1>"}]}))

Inline image

(require '[clojure.java.io :as io]
         '[tarayo.mail.mime.id :as mime-id])

(with-open [conn (tarayo/connect {:host "localhost" :port 25})]
  (let [content-id (mime-id/get-random)]
    (tarayo/send! conn {:from "alice@example.com"
                        :to "bob@example.com"
                        :subject "hello"
                        :body [{:content (str "<img src=\"cid:" content-id "\" /> world") :content-type "text/html}
                               ;; containing id will be handled as "inline attachment file"
                               {:content (io/file "/image.png") :id content-id}]})))

Stubbing

Example using shrubbery.

(require '[shrubbery.core :as shrubbery])

(let [conn (shrubbery/stub
            tarayo/ISMTPConnection
            {:send! "ok"
             :connected? true
             :close true})]
  (sut/send! conn "foo"))

License

Copyright 2020 TOYOKUMO,Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Can you improve this documentation?Edit on GitHub

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

× close