From 62597317839c7945bfbc4b7a00f55d2db6459ab6 Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Fri, 24 Apr 2015 12:53:02 -0400 Subject: Finally put pfifcontractors into git --- UtilEmail.hs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 UtilEmail.hs (limited to 'UtilEmail.hs') diff --git a/UtilEmail.hs b/UtilEmail.hs new file mode 100644 index 0000000..e81949f --- /dev/null +++ b/UtilEmail.hs @@ -0,0 +1,56 @@ +{-# LANGUAGE TupleSections, OverloadedStrings #-} +module UtilEmail where + +import Import +import qualified Data.Text.Lazy.Encoding +import Network.Mail.Mime (Part(..), Encoding(..), Address(..), Mail(..), emptyMail, renderSendMail, randomString) +import Text.Blaze.Renderer.Utf8 (renderHtml) +import Text.Hamlet (shamlet) +import Text.Shakespeare.Text (stext) + +import qualified Data.Text as T +import System.Random (newStdGen) + +sendVerifyEmail :: Text -> Text -> Text -> Handler () +sendVerifyEmail email _ verurl = + liftIO $ renderSendMail (emptyMail $ Address (Just "PFIF") "noreply@protocolfreedom.org") + { mailTo = [Address Nothing email] + , mailHeaders = + [ ("Subject", "Verify your email address") + ] + , mailParts = [[textPart, htmlPart]] + } + where + textPart = Part + { partType = "text/plain; charset=utf-8" + , partEncoding = None + , partFilename = Nothing + , partContent = Data.Text.Lazy.Encoding.encodeUtf8 [stext| +Please confirm your email address by visiting the link below. + +( #{verurl} ) + +Thank you, + +PFIF +|] + , partHeaders = [] + } + htmlPart = Part + { partType = "text/html; charset=utf-8" + , partEncoding = None + , partFilename = Nothing + , partContent = renderHtml [shamlet| +

Please confirm your email address by clicking on the link below. +

+ #{verurl} +

Thank you +|] + , partHeaders = [] + } + + +randomKey :: IO Text +randomKey = do + stdgen <- newStdGen + return $ T.pack $ fst $ randomString 10 stdgen -- cgit v1.2.3