Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- module Network.API.Mandrill.Types
- module Network.API.Mandrill.Trans
- module Network.API.Mandrill.Messages.Types
- module Network.API.Mandrill.Messages
- sendEmail :: MonadIO m => MandrillMessage -> MandrillT m (MandrillResponse [MessagesResponse])
- sendTextEmail :: MonadIO m => MandrillMessage -> MandrillT m (MandrillResponse [MessagesResponse])
- emptyMessage :: Maybe EmailAddress -> [EmailAddress] -> MandrillMessage
- newTextMessage :: EmailAddress -> [EmailAddress] -> Text -> Text -> MandrillMessage
- newHtmlMessage :: EmailAddress -> [EmailAddress] -> Text -> Html -> MandrillMessage
- newTemplateMessage :: EmailAddress -> [EmailAddress] -> Text -> MandrillMessage
- newTemplateMessage' :: [EmailAddress] -> MandrillMessage
- liftIO :: MonadIO m => IO a -> m a
Documentation
module Network.API.Mandrill.Types
module Network.API.Mandrill.Trans
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 level function for sending email.
sendTextEmail :: MonadIO m => MandrillMessage -> MandrillT m (MandrillResponse [MessagesResponse]) Source #
emptyMessage :: Maybe 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.
:: 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.
:: EmailAddress | Sender email |
-> [EmailAddress] | Receivers email |
-> Text | Subject |
-> Html | The HTML body |
-> MandrillMessage |
Create a new HTML message.
:: EmailAddress | Sender email |
-> [EmailAddress] | Receivers email |
-> Text | Subject |
-> MandrillMessage |
Create a new template message (no HTML).
:: [EmailAddress] | Receivers email |
-> MandrillMessage |
Create a new template message (no HTML) with recipient addresses only. This function is preferred when the template being used has the sender address and subject already configured in the Mandrill server.
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)