(ns foo.core
(:require [tarayo.core :as tarayo]))
Tarayo is heavily inspired by drewr/postal.
Only targets SMTP
Provide only one feature.
Use drewr/postal for sendmail
.
Explicit connection
Handle the connection manually.
Well tested
"Tarayo" is a tree name called "Tree of post office" in Japan.
(ns foo.core
(:require [tarayo.core :as tarayo]))
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:
(tarayo/connect {:host "localhost" :port 465 :ssl true})
(tarayo/connect {:host "localhost" :port 587 :tls true})
(tarayo/connect {:host "localhost" :port 25 :user "USERNAME" :password "PASSWORD"})
(with-open [conn (tarayo/connect {:host "localhost" :port 25})]
(tarayo/send! conn {:from "alice@example.com"
:to "bob@example.com"
:subject "hello"
:body "world"}))
(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>"}))
(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"}]}))
(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>"}]}))
(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}]})))
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