From 3c2e9d9298aaee21acef44be8b59136edf1cc0ce Mon Sep 17 00:00:00 2001 From: "Daniel P. Wright" Date: Tue, 27 Aug 2013 09:16:56 +0900 Subject: [PATCH] Add gmail IMAP/SMTP example --- examples/gmail.hs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 examples/gmail.hs diff --git a/examples/gmail.hs b/examples/gmail.hs new file mode 100644 index 0000000..7891652 --- /dev/null +++ b/examples/gmail.hs @@ -0,0 +1,38 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Network.HaskellNet.IMAP +import Network.HaskellNet.IMAP.SSL + +import Network.HaskellNet.SMTP +import Network.HaskellNet.SMTP.SSL + +import Network.HaskellNet.Auth (AuthType(PLAIN)) + +import Network.BSD (getHostName) +import qualified Data.ByteString.Char8 as B + +username = "username@gmail.com" +password = "password" +recipient = "someone@somewhere.com" + +imapTest = do + c <- connectIMAPSSL "imap.gmail.com" + login c username password + mboxes <- list c + mapM_ print mboxes + select c "INBOX" + msgs <- search c [ALLs] + let firstMsg = head msgs + msgContent <- fetch c firstMsg + B.putStrLn msgContent + +smtpTest = do + c <- connectSMTPSTARTTLS "smtp.gmail.com" + sendCommand c $ AUTH PLAIN username password + sendMail username [recipient] mailContent c + where mailContent = subject `B.append` body + subject = "Subject: Test message\r\n\r\n" + body = "This is a test message" + +main :: IO () +main = smtpTest >> imapTest >> return ()