blob: 5fc2f24353f30c081b22d6a804761b99bbc8935e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
{-# LANGUAGE OverloadedStrings #-}
module Mail
( sendMail
) where
import Data.Text (Text)
import qualified Data.Text as T
import Control.Exception (SomeException, try)
import Network.Email.Sendmail (sendmail)
import Utils.Either (mapLeft)
sendMail :: [Text] -> Text -> Text -> IO (Either Text ())
sendMail mailTo subject message =
let from = Just "no-reply@leboncoin-listener.com"
in safeSendMail from (map T.unpack $ mailTo) (T.unpack $ makeBody subject message)
makeBody :: Text -> Text -> Text
makeBody subject message =
T.concat
[ "Subject: "
, subject
, "\n\n"
, message
]
safeSendMail :: Maybe String -> [String] -> String -> IO (Either Text ())
safeSendMail from to body =
mapLeft (T.pack . show) <$> (try (sendmail from to body) :: IO (Either SomeException ()))
|