gogol icon indicating copy to clipboard operation
gogol copied to clipboard

Could you provide a simple example of how gogol-gmail should be used?

Open abailly opened this issue 8 years ago • 2 comments

I understand this is very early stage work and there is a lot to do, but I am really like a hen before an egg while looking at http://hackage.haskell.org/package/gogol-gmail-0.1.0. I have no idea how to start using it. In particular, I don't see how this works with OAuth2 authentication flow...

Thanks for the great work in making this available in Haskell!

abailly avatar Sep 18 '16 06:09 abailly

I would also really appreciate even a fairly basic example of how to query a given GMail account.

franckrasolo avatar Jun 17 '17 04:06 franckrasolo

module Main
  ( main
  ) where

import Control.Lens ((.~), (<&>))
import Control.Monad.Trans.Resource (runResourceT)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Base64.URL as Base64URL
import qualified Network.Google as Google
import qualified Network.Google.Gmail as Gmail
import Network.HTTP.Client (newManager)
import Network.HTTP.Client.TLS (tlsManagerSettings)

import System.Environment (getArgs)
import System.IO (stderr)

main :: IO ()
main = do
  fname <- head <$> getArgs
  email <- Base64URL.encode <$> BS.readFile fname
  lgr <- Google.newLogger Google.Trace stderr
  mgr <- newManager tlsManagerSettings
  crd <- Google.getApplicationDefault mgr
  env <-
    Google.newEnvWith crd lgr mgr <&> (Google.envScopes .~ Gmail.gmailSendScope)
  r <-
    runResourceT . Google.runGoogle env . Google.send $
    Gmail.usersMessagesSend (Gmail.mRaw .~ Just email $ Gmail.message)
  print r

ip1981 avatar Nov 06 '17 14:11 ip1981