{-# LANGUAGE OverloadedStrings #-} module Main where import Config import Data.Time.Clock import Database.MongoDB import qualified Network.Mail.Mime as M import Network.Mail.SMTP import Owner import System.Exit main :: IO () main = do now <- getCurrentTime loadedConfig <- loadZGoConfig "zgo.cfg" pipe <- connect $ host (c_dbHost loadedConfig) let db = c_dbName loadedConfig x <- access pipe master db (auth (c_dbUser loadedConfig) (c_dbPassword loadedConfig)) if x then do putStrLn "Connected to MongoDB!" users <- access pipe master db $ findExpiringOwners now putStr "Expiring users: " print $ length users mapM_ (emailOwner loadedConfig) users else die "MongoDB connection failed!" where emailOwner :: Config -> Document -> IO () emailOwner config doc = do let o = (cast' . Doc) doc case o of Nothing -> putStrLn "Couldn't parse owner record." Just o1 -> do mail <- M.simpleMail (Address (Just $ oname o1) (oemail o1)) (Address (Just "ZGo Support") "contact@zgo.cash") "ZGo session about to expire" "Your ZGo session is about to expire" "
Your ZGo session is about to expire
" [] sendMailWithLogin' "127.0.0.1" 1025 "contact@zgo.cash" "uib3K8BkCPexl_wr5bYfrg" mail