mandrill-0.5.1.0: Library for interfacing with the Mandrill JSON API

Safe HaskellNone
LanguageHaskell2010

Network.API.Mandrill

Contents

Description

This package is an attempt to expose the Mandrill JSON API in pure Haskell. To do that, the library API comes in two flavours:

  • An IO-based, low-level 1:1 mapping of the JSON API, as described on the website.
  • A handy monad transformer which can be plugged in your stack of choice.

Synopsis

Documentation

sendEmail :: MonadIO m => MandrillMessage -> MandrillT m (MandrillResponse [MessagesResponse]) Source

The simplest way to use the API. All you need to provide is a valid MandrillMessage and this function will send an email inside a MandrillT transformer. You are not forced to use the MandrillT context though. Have a look at Network.API.Mandrill.Messages for an IO-based, low lever function for sending email.

emptyMessage :: EmailAddress -> [EmailAddress] -> MandrillMessage Source

Builds an empty message, given only the email of the sender and the emails of the receiver. Please note that the Subject will be empty, so you need to use either newTextMessage or newHtmlMessage to populate it.

newTextMessage Source

Arguments

:: EmailAddress

Sender email

-> [EmailAddress]

Receivers email

-> Text

Subject

-> Text

The body, as normal text.

-> MandrillMessage 

Create a new textual message. By default Mandrill doesn't require you to specify the mmsg_text when sending out the JSON Payload, and this function ensure it will be present.

newHtmlMessage Source

Arguments

:: EmailAddress

Sender email

-> [EmailAddress]

Receivers email

-> Text

Subject

-> Html

The HTML body

-> MandrillMessage 

Create a new HTML message.

newTemplateMessage Source

Arguments

:: EmailAddress

Sender email

-> [EmailAddress]

Receivers email

-> Text

Subject

-> MandrillMessage 

Create a new template message (no HTML).

liftIO :: MonadIO m => forall a. IO a -> m a

Lift a computation from the IO monad.

Appendix: Example Usage

The API was designed to allow to get you started as quickly as possible:

import Text.Email.Validate
import Network.API.Mandrill

main :: IO ()
main = do
  case validate "foo@example.com" of
    Left err   -> print $ "Invalid email!" ++ show err
    Right addr -> runMandrill "MYTOKENHERE" $ do
      let msg = "<p>My Html</p>"
      res <- sendEmail (newTextMessage addr [addr] "Hello" msg)
      case res of
        MandrillSuccess k -> liftIO (print k)
        MandrillFailure f -> liftIO (print f)