riemann.mailgun

Forwards events to Mailgun

mailgun

(mailgun)(mailgun opts)(mailgun mgun-opts msg-opts)

Returns a mailer, which is a function invoked with an address or a sequence of addresses and returns a stream. That stream is a function which takes a single event, or a sequence of events, and sends email about them.

(def mailer (mailgun))
(def email (mailer "xerxes@trioptimum.org" "shodan@trioptimum.org"))

This mailer sends email out via mailgun using the mailgun http api. When used it outputs the http response recieved from mailgun.

(changed :state
  #(info "mailgun response" (email %)))

The first argument is a map of the mailgun options :sandbox and :service-key. The second argument is a map of default message options, like :from, :subject, or :body.

(def email (mailgun {:sandbox "mail.relay" :service-key "key"}
                    {:from "riemann@trioptimum.com"}))

If you provide a single map, the mailer will split the mailgun options out for you.

(def email (mailgun {:sandbox "mail.relay"
                     :service-key "foo"
                     :from "riemann@trioptimum.com"}))

By default, riemann uses (subject events) and (body events) to format emails. You can set your own subject or body formatter functions by including :subject or :body in msg-opts. These formatting functions take a sequence of events and return a string.

(def email (mailgun {} {:body (fn [events]
                               (apply prn-str events))}))

This api uses text body by default. If you want to use HTML body, you can set a body formatter function returns a map of fields :type and :content.

(def email (mailgun {} {:body (fn [events]
                               {:type :html
                                :content "<h1>HTML Body</h1>"})}))

mailgun-event

(mailgun-event mgun-opts msg-opts events)

Send an event, or a sequence of events, with the given smtp and msg options.