diff options
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 ())) |