diff options
author | Joris Guyonvarch | 2015-08-09 00:21:03 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2015-08-09 00:21:03 +0200 |
commit | 169d52bfbe8b7f95dcece3cef245cdd62336e2f8 (patch) | |
tree | 491b5edb2646b41d36920f1c670cba26a674868c /src/server/Mail.hs | |
parent | a4f60df0f3b72553380bdd3ca960abf42048ed7e (diff) | |
download | budget-169d52bfbe8b7f95dcece3cef245cdd62336e2f8.tar.gz budget-169d52bfbe8b7f95dcece3cef245cdd62336e2f8.tar.bz2 budget-169d52bfbe8b7f95dcece3cef245cdd62336e2f8.zip |
Wording for sign in email
Diffstat (limited to 'src/server/Mail.hs')
-rw-r--r-- | src/server/Mail.hs | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/src/server/Mail.hs b/src/server/Mail.hs deleted file mode 100644 index c649d59..0000000 --- a/src/server/Mail.hs +++ /dev/null @@ -1,58 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module Mail - ( Mail(..) - , sendMail - ) where - -import Data.Text (Text) -import qualified Data.Text as T -import qualified Data.Text.Lazy as LT -import Data.Text.Lazy.Builder (toLazyText, fromText) -import Data.Either (isLeft) - -import Control.Exception (SomeException, try) - -import qualified Network.Mail.Mime as M - -data Mail = Mail - { to :: [Text] - , subject :: Text - , plainBody :: Text - , htmlBody :: Text - } deriving (Eq, Show) - -sendMail :: Mail -> IO (Either Text ()) -sendMail mail = do - result <- mapLeft (T.pack . show) <$> (try (M.renderSendMail . getMimeMail $ mail) :: IO (Either SomeException ())) - if isLeft result - then putStrLn ("Error sending the following email:" ++ (show mail)) - else return () - return result - -mapLeft :: (a -> c) -> Either a b -> Either c b -mapLeft f (Left l) = Left (f l) -mapLeft _ (Right r) = (Right r) - -getMimeMail :: Mail -> M.Mail -getMimeMail (Mail to subject plainBody htmlBody) = - let fromMail = M.emptyMail (address "no-reply@shared-cost.guyonvarch.me") - in fromMail - { M.mailTo = map address to - , M.mailParts = - [ [ M.plainPart . strictToLazy $ plainBody - , M.htmlPart . strictToLazy $ htmlBody - ] - ] - , M.mailHeaders = [("Subject", subject)] - } - -strictToLazy :: Text -> LT.Text -strictToLazy = toLazyText . fromText - -address :: Text -> M.Address -address addressEmail = - M.Address - { M.addressName = Nothing - , M.addressEmail = addressEmail - } |