mime-mail-0.4.12: Compose MIME email messages.

Safe Haskell | None
Language | Haskell98

Network.Mail.Mime

Contents

- Datatypes
- Render a message
- Sending messages
- High-level `Mail` creation
- Utilities

Synopsis

- newtype Boundary = Boundary {
  - unBoundary :: Text
  }
- data Mail = Mail {
  - mailFrom :: Address
  - mailTo :: [Address]
  - mailCc :: [Address]
  - mailBcc :: [Address]
  - mailHeaders :: Headers
  - mailParts :: [Alternatives]
  }
- emptyMail :: Address -> Mail
- data Address = Address {
  - addressName :: Maybe Text
  - addressEmail :: Text
  }
- type Alternatives = [Part]
- data Part = Part {
  - partType :: Text
  - partEncoding :: Encoding
  - partFilename :: Maybe Text
  - partHeaders :: Headers
  - partContent :: ByteString
  }
- data Encoding
  - = None
  - | Base64
  - | QuotedPrintableText
  - | QuotedPrintableBinary
- type Headers = [(ByteString, Text)]
- renderMail :: RandomGen g => g -> Mail -> (ByteString, g)
- renderMail' :: Mail -> IO ByteString
- sendmail :: ByteString -> IO ()
- sendmailCustom :: FilePath -> [String] -> ByteString -> IO ()
- sendmailCustomCaptureOutput :: FilePath -> [String] -> ByteString -> IO (ByteString, ByteString)
- renderSendMail :: Mail -> IO ()
- renderSendMailCustom :: FilePath -> [String] -> Mail -> IO ()
- simpleMail :: Address -> Address -> Text -> Text -> Text -> [(Text, FilePath)] -> IO Mail
- simpleMail' :: Address -> Address -> Text -> Text -> Mail
- simpleMailInMemory :: Address -> Address -> Text -> Text -> Text -> [(Text, Text, ByteString)] -> Mail
- addPart :: Alternatives -> Mail -> Mail
- addAttachment :: Text -> FilePath -> Mail -> IO Mail
- addAttachmentCid :: Text -> FilePath -> Text -> Mail -> IO Mail
- addAttachments :: [(Text, FilePath)] -> Mail -> IO Mail
- addAttachmentBS :: Text -> Text -> ByteString -> Mail -> Mail
- addAttachmentBSCid :: Text -> Text -> ByteString -> Text -> Mail -> Mail
- addAttachmentsBS :: [(Text, Text, ByteString)] -> Mail -> Mail
- renderAddress :: Address -> Text
- htmlPart :: Text -> Part
- plainPart :: Text -> Part
- randomString :: RandomGen d => Int -> d -> (String, d)
- quotedPrintable :: Bool -> ByteString -> Builder

# Datatypes

newtype Boundary #

MIME boundary between parts of a message.

Constructors

Boundary |
Fields unBoundary :: Text

Instances

Eq Boundary # |
Methods (==) :: Boundary -> Boundary -> Bool # (/=) :: Boundary -> Boundary -> Bool #
Show Boundary # |
Methods showsPrec :: Int -> Boundary -> ShowS # show :: Boundary -> String # showList :: [Boundary] -> ShowS #
Random Boundary # |
Methods randomR :: RandomGen g => (Boundary, Boundary) -> g -> (Boundary, g) # random :: RandomGen g => g -> (Boundary, g) # randomRs :: RandomGen g => (Boundary, Boundary) -> g -> [Boundary] # randoms :: RandomGen g => g -> [Boundary] # randomRIO :: (Boundary, Boundary) -> IO Boundary # randomIO :: IO Boundary #

data Mail #

An entire mail message.

Constructors

Mail |
- Fields mailFrom :: Address mailTo :: [Address] mailCc :: [Address] mailBcc :: [Address] mailHeaders :: Headers Other headers, excluding from, to, cc and bcc. mailParts :: [Alternatives] A list of different sets of alternatives. As a concrete example:
      mailParts = [ [textVersion, htmlVersion], [attachment1], [attachment1]]
Make sure when specifying alternatives to place the most preferred version last.

Instances

Show Mail # |
Methods showsPrec :: Int -> Mail -> ShowS # show :: Mail -> String # showList :: [Mail] -> ShowS #

emptyMail :: Address -> Mail #

A mail message with the provided `from` address and no other fields filled in.

data Address #

Constructors

Address |
Fields addressName :: Maybe Text addressEmail :: Text

Instances

Eq Address # |
Methods (==) :: Address -> Address -> Bool # (/=) :: Address -> Address -> Bool #
Show Address # |
Methods showsPrec :: Int -> Address -> ShowS # show :: Address -> String # showList :: [Address] -> ShowS #

type Alternatives = [Part] #

Multiple alternative representations of the same data. For example, you could provide a plain-text and HTML version of a message.

data Part #

A single part of a multipart message.

Constructors

Part |
Fields partType :: Text content type partEncoding :: Encoding partFilename :: Maybe Text The filename for this part, if it is to be sent with an attachemnt disposition. partHeaders :: Headers partContent :: ByteString

Instances

Eq Part # |
Methods (==) :: Part -> Part -> Bool # (/=) :: Part -> Part -> Bool #
Show Part # |
Methods showsPrec :: Int -> Part -> ShowS # show :: Part -> String # showList :: [Part] -> ShowS #

data Encoding #

How to encode a single part. You should use `Base64` for binary data.

Constructors

None |
Base64 |
QuotedPrintableText |
QuotedPrintableBinary |

Instances

Eq Encoding # |
Methods (==) :: Encoding -> Encoding -> Bool # (/=) :: Encoding -> Encoding -> Bool #
Show Encoding # |
Methods showsPrec :: Int -> Encoding -> ShowS # show :: Encoding -> String # showList :: [Encoding] -> ShowS #

type Headers = [(ByteString, Text)] #

# Render a message

renderMail :: RandomGen g => g -> Mail -> (ByteString, g) #

Render a `Mail` with a given `RandomGen` for producing boundaries.

renderMail' :: Mail -> IO ByteString #

Like `renderMail`, but generates a random boundary.

# Sending messages

sendmail :: ByteString -> IO () #

Send a fully-formed email message via the default sendmail executable with default options.

sendmailCustom #

Arguments

:: FilePath | sendmail executable path
-> [String] | sendmail command-line options
-> ByteString | mail message as lazy bytestring
-> IO () |

Send a fully-formed email message via the specified sendmail executable with specified options.

sendmailCustomCaptureOutput :: FilePath -> [String] -> ByteString -> IO (ByteString, ByteString) #

Like `sendmailCustom`, but also returns sendmail's output to stderr and stdout as strict ByteStrings.

Since 0.4.9

renderSendMail :: Mail -> IO () #

Render an email message and send via the default sendmail executable with default options.

renderSendMailCustom #

Arguments

:: FilePath | sendmail executable path
-> [String] | sendmail command-line options
-> Mail | mail to render and send
-> IO () |

Render an email message and send via the specified sendmail executable with specified options.

# High-level `Mail` creation

simpleMail #

Arguments

:: Address | to
-> Address | from
-> Text | subject
-> Text | plain body
-> Text | HTML body
-> [(Text, FilePath)] | content type and path of attachments
-> IO Mail |

A simple interface for generating an email with HTML and plain-text alternatives and some file attachments.

Note that we use lazy IO for reading in the attachment contents.

simpleMail' #

Arguments

:: Address | to
-> Address | from
-> Text | subject
-> Text | body
-> Mail |

A simple interface for generating an email with only plain-text body.

simpleMailInMemory #

Arguments

:: Address | to
-> Address | from
-> Text | subject
-> Text | plain body
-> Text | HTML body
-> [(Text, Text, ByteString)] | content type, file name and contents of attachments
-> Mail |

A simple interface for generating an email with HTML and plain-text alternatives and some `ByteString` attachments.

Since 0.4.7

# Utilities

addPart :: Alternatives -> Mail -> Mail #

Add an `Alternative` to the `Mail`s parts.

To e.g. add a plain text body use > addPart [plainPart body] (emptyMail from)

addAttachment :: Text -> FilePath -> Mail -> IO Mail #

Add an attachment from a file and construct a `Part`.

addAttachmentCid #

Arguments

:: Text | content type
-> FilePath | file name
-> Text | content ID
-> Mail |
-> IO Mail |

Add an attachment from a file and construct a `Part` with the specified content id in the Content-ID header.

Since: 0.4.12

addAttachments :: [(Text, FilePath)] -> Mail -> IO Mail #

addAttachmentBS #

Arguments

:: Text | content type
-> Text | file name
-> ByteString | content
-> Mail |
-> Mail |

Add an attachment from a `ByteString` and construct a `Part`.

Since 0.4.7

addAttachmentBSCid #

Arguments

:: Text | content type
-> Text | file name
-> ByteString | content
-> Text | content ID
-> Mail |
-> Mail |

Since: 0.4.12

addAttachmentsBS :: [(Text, Text, ByteString)] -> Mail -> Mail #

Since 0.4.7

renderAddress :: Address -> Text #

Format an E-Mail address according to the name-addr form (see: RFC5322 § 3.4 "Address specification", i.e: [display-name] '<'addr-spec'>') This can be handy for adding custom headers that require such format.

Since: 0.4.11

htmlPart :: Text -> Part #

Construct a UTF-8-encoded html `Part`.

plainPart :: Text -> Part #

Construct a UTF-8-encoded plain-text `Part`.

randomString :: RandomGen d => Int -> d -> (String, d) #

Generates a random sequence of alphanumerics of the given length.

quotedPrintable :: Bool -> ByteString -> Builder #

The first parameter denotes whether the input should be treated as text. If treated as text, then CRs will be stripped and LFs output as CRLFs. If binary, then CRs and LFs will be escaped.