Making it easy to send SMTP email from Haskell
Haskell
Switch branches/tags
Nothing to show
Clone or download
parsonsmatt v0.1.4.6
- Add `connectSMTPWithHostName`, allowing clients to provide their own
  functions for retrieving a host name.
- Add `sendMailWithSender`, allowing clients to provide a different
  Sender attribute than the 'from' address.
Latest commit da590c4 Dec 7, 2016
Permalink
Failed to load latest commit information.
Network/Mail Ability to specify from hostname (#20) Dec 7, 2016
.gitignore version bump Jan 17, 2013
LICENSE v0.1.4.6 Dec 7, 2016
README.md Fixed a typo in the ReadMe. Jan 7, 2013
Setup.hs initial Dec 14, 2012
smtp-mail.cabal v0.1.4.6 Dec 7, 2016

README.md

SMTP-MAIL

Making it easy to send SMTP emails from Haskell.

cabal install smtp-mail

Sending with an SMTP server

{-# LANGUAGE OverloadedStrings #-}

import Network.Mail.SMTP

from       = Address Nothing "email@domain.com"
to         = [Address (Just "Jason Hickner") "email@domain.com"]
cc         = []
bcc        = []
subject    = "email subject"
body       = plainTextPart "email body"
html       = htmlPart "<h1>HTML</h1>"

mail = simpleMail from to cc bcc subject [body, html]

main = sendMail host mail

or with an attachment:

main = do
  attachment <- filePart "application/octet-stream" "path/to/attachment.zip"
  let mail = simpleMail from to cc bcc subject [body, html, attachment]
  sendMail host mail

or, with authentication:

main = sendMailWithLogin host user pass mail

Note: sendMail' and sendMailWithLogin' variations are also provided if you want to specify a port as well as a hostname.

Sending with sendmail

If you'd like to use sendmail, the sendmail interface from Network.Mail.Mime is reexported as well:

-- send via the default sendmail executable with default options
renderSendMail mail

-- send via the specified executable with specified options
renderSendMailCustom filepath [opts] mail

For more complicated scenarios or for adding attachments or CC/BCC addresses you can import Network.Mail.Mime and construct Mail objects manually.

Thanks

This library is based on code from HaskellNet, which appears to be no longer maintained. I've cleaned up the error handling, added some API functions to make common operations easier, and switched to ByteStrings where applicable.