1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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|
<p>Please confirm your email address by clicking on the link below.
<p>
<a href=#{verurl}>#{verurl}
<p>Thank you
|]
, partHeaders = []
}
randomKey :: IO Text
randomKey = do
stdgen <- newStdGen
return $ T.pack $ fst $ randomString 10 stdgen
|