From d3dd0e129658e3617f9e6e4fa0910cb15c42520d Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Tue, 14 Apr 2015 00:10:21 +0200 Subject: Send mail to notify for new ads --- src/Mail.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/Mail.hs (limited to 'src/Mail.hs') diff --git a/src/Mail.hs b/src/Mail.hs new file mode 100644 index 0000000..bb96142 --- /dev/null +++ b/src/Mail.hs @@ -0,0 +1,21 @@ +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 -> IO (Either Text ()) +sendMail mailTo body = + let from = Just "no-reply@leboncoin-listener.com" + in safeSendMail from (map T.unpack $ mailTo) (T.unpack body) + +safeSendMail :: Maybe String -> [String] -> String -> IO (Either Text ()) +safeSendMail from to body = + mapLeft (T.pack . show) <$> (try (sendmail from to body) :: IO (Either SomeException ())) -- cgit v1.2.3