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
43
43
network-bsd >= 2.7 && < 2.9
44
44
else
45
45
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 3
3
import Network.HaskellNet.IMAP.SSL
4
4
import Network.HaskellNet.SMTP.SSL as SMTP
5
5
6
- import Network.HaskellNet.Auth (AuthType (LOGIN ))
6
+ import Network.HaskellNet.Auth (AuthType (LOGIN ), Password )
7
+ import Network.Mail.Mime
7
8
8
9
import qualified Data.ByteString.Char8 as B
10
+ import Data.String
9
11
12
+ username :: IsString s => s
10
13
14
+
15
+ password :: Password
11
16
password = " password"
17
+
18
+ recipient :: Address
12
19
13
20
21
+ imapTest :: IO ()
14
22
imapTest = do
15
23
c <- connectIMAPSSLWithSettings " imap.gmail.com" cfg
16
24
login c username password
17
25
mboxes <- list c
18
26
mapM_ print mboxes
19
27
select c " INBOX"
20
- msgs <- search c [ALLs ]
21
- let firstMsg = head msgs
28
+ msgs@ (firstMsg : _) <- search c [ALLs ]
22
29
msgContent <- fetch c firstMsg
23
30
B. putStrLn msgContent
24
31
logout c
25
32
where cfg = defaultSettingsIMAPSSL { sslMaxLineLength = 100000 }
26
33
34
+ smtpTest :: IO ()
27
35
smtpTest = doSMTPSTARTTLS " smtp.gmail.com" $ \ c -> do
28
36
authSucceed <- SMTP. authenticate LOGIN username password c
29
37
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
31
47
else print " Authentication error."
32
48
where subject = " Test message"
33
49
body = " This is a test message"
34
50
35
51
main :: 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