hailgun- Mailgun REST api interface for Haskell.

Safe HaskellNone



Hailgun is a Haskell wrapper around the Mailgun api's that use type safety to ensure that you are sending a valid request to the Mailgun API's. Mailgun is a service that lets you send emails. It also contains a number of other email handling API's that will be implimented in the future.



sendEmail Source


:: HailgunContext

The Mailgun context to operate in.

-> HailgunMessage

The Hailgun message to be sent.

-> IO (Either HailgunErrorResponse HailgunSendResponse)

The result of the sent email. Either a sent email or a successful send.

Send an email using the Mailgun API's. This method is capable of sending a message over the Mailgun service. All it needs is the appropriate context.

hailgunMessage Source


:: MessageSubject

The purpose of the email surmised.

-> MessageContent

The full body of the email.

-> UnverifiedEmailAddress

The email account that the recipients should respond to in order to get back to us.

-> MessageRecipients

The people that should recieve this email.

-> [Attachment]

The attachments that you want to attach to the email; standard or inline.

-> Either HailgunErrorMessage HailgunMessage

Either an error while trying to create a valid message or a valid message.

A method to construct a HailgunMessage. You require a subject, content, From address and people to send the email to and it will give you back a valid Hailgun email message. Or it will error out while trying.

addAttachment :: Attachment -> Endo HailgunMessage Source

Allows you to add an attachment to an already created HailgunMessage. But please note that it will only add your attachment as a standard attachment. Inline attachments must be added at the time that the HailgunMessage was created.

data HailgunContext Source

When comunnicating to the Mailgun service you need to have some common pieces of information to authenticate successfully. This context encapsulates that required information.




hailgunDomain :: String

The domain of the mailgun account that you wish to send the emails through.

hailgunApiKey :: String

The API key for the mailgun account so that you can successfully make requests. Please note that it should include the key prefix.

hailgunProxy :: Maybe Proxy

data HailgunMessage Source

A Hailgun Email message that may be sent. It contains important information such as the address that the email is from, the addresses that it should be going to, the subject of the message and the content of the message. Any email that you wish to send via this api must be converted into this structure first. To create a message then please use the hailgunMessage interface.

type MessageSubject Source


 = Text

Represents a message subject.

data MessageContent Source

Any email content that you wish to send should be encoded into these types before it is sent. Currently, according to the API, you should always send a Text Only part in the email and you can optionally add a nicely formatted HTML version of that email to the sent message.

It is best to send multi-part emails using both text and HTML or text only. Sending HTML only
email is not well received by ESPs.


This API mirrors that advice so that you can always get it right.



The Text only version of the message content.


textContent :: ByteString

The text content that you wish to send (please note that many clients will take the HTML version first if it is present but that the text version is a great fallback).


A message that contains both a Text version of the email content and a HTML version of the email content.


textContent :: ByteString

The text content that you wish to send (please note that many clients will take the HTML version first if it is present but that the text version is a great fallback).

htmlContent :: ByteString

The HTML content that you wish to send.

data MessageRecipients Source

A collection of unverified email recipients separated into the To, CC and BCC groupings that email supports.




recipientsTo :: [UnverifiedEmailAddress]

The people to email directly.

recipientsCC :: [UnverifiedEmailAddress]

The people to "Carbon Copy" into the email. Honestly, why is that term not deprecated yet?

recipientsBCC :: [UnverifiedEmailAddress]

The people to "Blind Carbon Copy" into the email. There really needs to be a better name for this too.

emptyMessageRecipients :: MessageRecipients Source

No recipients for your email. Useful singleton instance to avoid boilerplate in your code. For example:

toBob = emptyMessageRecipients { recipientsTo = ["bob@bob.test"] }

type UnverifiedEmailAddress Source


 = ByteString

Represents an email address that is not yet verified.

data HailgunSendResponse Source

The response to an email being accepted by the Mailgun API.




hsrMessage :: String

The freeform message from the mailgun API.

hsrId :: String

The ID of the message that has been accepted by the Mailgun api.

type HailgunErrorMessage = String Source

A generic error message that is returned by the Hailgun library.

data HailgunErrorResponse Source

An error that comes from Mailgun or the Hailgun API.




herMessage :: String

A generic message describing the error.

getDomains Source


:: HailgunContext

The context to operate in which specifies which account to get the domains from.

-> Page

The page of results that you wish to see returned.

-> IO (Either HailgunErrorResponse HailgunDomainResponse)

The IO response which is either an error or the list of domains.

Make a request to Mailgun for the domains against your account. This is a paginated request so you must specify the pages of results that you wish to get back.

data Page Source

Represents a single page of results. You specify a page of results when you wish to to make a request to a paginated resource.



newtype HailgunTime Source

A wrapper for UTCTime so that we can always pass correctly formatted times to Mailgun.


HailgunTime UTCTime 

toProxy Source


:: String

The proxy host

-> Int

The proxy port

-> Proxy

The proxy configuration.

A convinience method to create a proxy for the HailgunContext.

data Attachment Source

An Attachment that may be sent. It contains the file path of the attachment and the data that you wish to send in the attachment body. It is important to note that this data type makes no distinction between standard attachments and HTML inline attachments. See sendEmail for more details on how to make your attachments behave like inline attachments.

data AttachmentBody Source

An Attachment body is the raw data that you want to send with your attachment.


AttachmentBS ByteString

A strict ByteString representation of your data.

AttachmentLBS ByteString

A lazy ByteString representation of your data.