(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.enable true})
(tarayo/connect {:host "localhost" :port 587 :starttls.enable 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 [;; 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"}]}))
(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>"}]}))
(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}]})))
Example using shrubbery.
(require '[shrubbery.core :as shrubbery])
(let [conn (shrubbery/stub
tarayo/ISMTPConnection
{:send! "ok"
:connected? true
:close true})]
(sut/send! conn "foo"))
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