smtp-mail: Simple email sending via SMTP

[ bsd3, library, network ] [ Propose Tags ]

This packages provides a simple interface for mail over SMTP. Please see the README for more information.

[Skip to Readme]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS],,,,,,,,,,,,,,,,,
Change log
Dependencies array, base (>=4.5 && <5), base16-bytestring, base64-bytestring, bytestring, crypton (<1 || >=1.0 && <1.1), crypton-connection (>=0.3.1 && <0.4 || >=0.4.0 && <0.5), data-default-class (>= && <0.2), filepath, memory, mime-mail, network, network-bsd, text [details]
License BSD-3-Clause
Author Jason Hickner, Matt Parsons
Category Network
Home page
Source repo head: git clone
Uploaded by SpencerJanssen at 2024-07-16T15:50:21Z
Distributions Debian:, NixOS:, Stackage:
Reverse Dependencies 3 direct, 0 indirect [details]
Downloads 15622 total (194 in the last 30 days)
Rating 2.25 (votes: 4) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-07-16 [all 1 reports]

Readme for smtp-mail-

[back to package description]


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


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.


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.