BSD-3-Clause licensed by Jason Hickner, Matt Parsons
Maintained by [email protected]
This version can be pinned in stack with:smtp-mail-0.5.0.0@sha256:3056eab06ddeaa47b4f5748107d16b43883421899f90fc7dfef561ea23149d33,1390

Module documentation for 0.5.0.0

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 protected]"
to         = [Address (Just "Jason Hickner") "[email protected]"]
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

or, using STARTTLS:

main = sendMailSTARTTLS host mail

or, using SMTPS:

main = sendMailTLS host 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.

Developing

nix-integration-test/ contains a integration test, which uses nixos qemu vm tests to start a qemu vm with a postfix and use smtp-mail to send mails to that postfix.

Install nix, enable flakes and execute nix flake check to execute the test. Success is signalled by a return code of 0.

Changes

CHANGELOG

This package follows the Package Versioning Policy. Roughly speaking, this means that we have four digits standing for:

  • Major: A significant rewrite of the library.
  • Major: A breaking change
  • Minor: A non-breaking addition
  • Patch: A non-breaking bugfix

Upcoming

If you are doing a pull-request, please update this list. A template is provided:

- [# PR number](URL to pr) @your_github_username
  - Describe change #1
  - Describe change #2
  - Indicate if changes are major, minor, or patch changes.

0.5.0.0

  • Adds support for OAuth authentication with a new function sendMailWithLoginOAuthSTARTTLS.

0.4.0.2

  • Switch to crypton because the cryptonite package is no longer maintained.

0.4.0.1

  • #11 @spencerjanssen
    • Support crypton-connection-0.4.0

0.4.0.0

  • #5 @spencerjanssen
    • Switch to crypton-connection because the connection package is no longer maintained
  • #6 @spencerjanssen

0.3.0.0

  • #32 @typetetris

    • add some functions to use SMTPS, which should be preferred to STARTTLS for mail submissions of endusers according to RFC 8314
    • add STARTTLS
    • add integration test using nixos tests
  • #30 @typetetris

    • Replace cryptohash dependency with cryptonite. cryptohash is deprecated and cryptonite offers HMAC MD5 directly.

0.2.0.0

  • #25 @shulhi
    • References to the deprecated Network module were removed and replaced with the new connection package.
    • Duplicate functionality was deprecated.
  • #23 @alexandersgreen
    • The Cc and Bcc fields will be sent to the SMTP server, and they’ll actually be sent now.