Safe Haskell | None |
---|---|
Language | Haskell2010 |
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.
- sendEmail :: MonadIO m => MandrillMessage -> MandrillT m (MandrillResponse [MessagesResponse])
- sendTextEmail :: MonadIO m => MandrillMessage -> MandrillT m (MandrillResponse [MessagesResponse])
- emptyMessage :: EmailAddress -> [EmailAddress] -> MandrillMessage
- newTextMessage :: EmailAddress -> [EmailAddress] -> Text -> Text -> MandrillMessage
- newHtmlMessage :: EmailAddress -> [EmailAddress] -> Text -> Html -> MandrillMessage
- newTemplateMessage :: EmailAddress -> [EmailAddress] -> Text -> MandrillMessage
- liftIO :: MonadIO m => forall a. IO a -> m a
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.
sendTextEmail :: MonadIO m => MandrillMessage -> MandrillT m (MandrillResponse [MessagesResponse]) Source
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.
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.
Arguments
:: EmailAddress | Sender email |
-> [EmailAddress] | Receivers email |
-> Text | Subject |
-> Html | The HTML body |
-> MandrillMessage |
Create a new HTML message.
Arguments
:: EmailAddress | Sender email |
-> [EmailAddress] | Receivers email |
-> Text | Subject |
-> MandrillMessage |
Create a new template message (no HTML).
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)