diff options
author | Joris Guyonvarch | 2015-04-14 00:10:21 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2015-04-14 00:12:04 +0200 |
commit | d3dd0e129658e3617f9e6e4fa0910cb15c42520d (patch) | |
tree | 7eed51e2f4dd9c599daa1d9728a6ca8c86e3897e /src/Mail.hs | |
parent | a2c9ca0ee7022981fa563ed867e85cdeae3b1590 (diff) |
Send mail to notify for new ads
Diffstat (limited to 'src/Mail.hs')
-rw-r--r-- | src/Mail.hs | 21 |
1 files changed, 21 insertions, 0 deletions
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 ())) |