File tree Expand file tree Collapse file tree 2 files changed +35
-5
lines changed
Expand file tree Collapse file tree 2 files changed +35
-5
lines changed Original file line number Diff line number Diff line change @@ -43,3 +43,15 @@ library
4343 network-bsd >= 2.7 && < 2.9
4444 else
4545 build-depends : network >= 2.4 && < 3.0
46+
47+ executable HaskellNet-SSL-example
48+ hs-source-dirs : examples
49+ main-is : gmail.hs
50+ other-modules :
51+ build-depends :
52+ base < 5
53+ , HaskellNet-SSL
54+ , HaskellNet
55+ , bytestring
56+
57+ default-language : Haskell2010
Original file line number Diff line number Diff line change 33import Network.HaskellNet.IMAP.SSL
44import Network.HaskellNet.SMTP.SSL as SMTP
55
6- import Network.HaskellNet.Auth (AuthType (LOGIN ))
6+ import Network.HaskellNet.Auth (AuthType (LOGIN ), Password )
7+ import Network.Mail.Mime
78
89import qualified Data.ByteString.Char8 as B
10+ import Data.String
911
12+ username :: IsString s => s
101314+
15+ password :: Password
1116password = " password"
17+
18+ recipient :: Address
12191320
21+ imapTest :: IO ()
1422imapTest = do
1523 c <- connectIMAPSSLWithSettings " imap.gmail.com" cfg
1624 login c username password
1725 mboxes <- list c
1826 mapM_ print mboxes
1927 select c " INBOX"
20- msgs <- search c [ALLs ]
21- let firstMsg = head msgs
28+ msgs@ (firstMsg : _) <- search c [ALLs ]
2229 msgContent <- fetch c firstMsg
2330 B. putStrLn msgContent
2431 logout c
2532 where cfg = defaultSettingsIMAPSSL { sslMaxLineLength = 100000 }
2633
34+ smtpTest :: IO ()
2735smtpTest = doSMTPSTARTTLS " smtp.gmail.com" $ \ c -> do
2836 authSucceed <- SMTP. authenticate LOGIN username password c
2937 if authSucceed
30- then sendPlainTextMail recipient username subject body c
38+ then do
39+ mail <- simpleMail
40+ recipient
41+ username
42+ subject
43+ body
44+ mempty
45+ mempty
46+ sendMail mail c -- recipient username subject body
3147 else print " Authentication error."
3248 where subject = " Test message"
3349 body = " This is a test message"
3450
3551main :: IO ()
36- main = smtpTest >> imapTest >> return ()
52+ main = do
53+ smtpTest
54+ imapTest
You can’t perform that action at this time.
0 commit comments