gmail-simple-0.1.0.6: Simple library for Google Mail (GMail).
Safe HaskellSafe-Inferred
LanguageHaskell2010

Network.GMail.Simple

Description

Interactions with GMail made simple.

Sending mails

For now, only mail sending is implemented. Here's an example:

First we read the Google key file.

do gkey <- readKeyFile "google-key.json"

Then we start a session. We provide the mail address of the user that will send the mail.

   session <- newSession gkey "sender@example.com"

Here's the mail description.

   let mail :: Mail Text
       mail = Mail
         { mail_sender = "Me"
         , mail_recipient = "recipient@example.com"
         , mail_subject = "Example mail"
         , mail_body = "This is an example mail."
           }

Finally, we simply send the mail.

   sendMail session mail

That's it.

Importing this library

I would recommend importing this module qualified. For example:

import qualified Network.GMail.Simple as GMail
Synopsis

Key

data Key Source #

Google API Key from a service account. You can create one inside your project in Google Cloud. Once you have it, you can download it to a file and read it using readKeyFile.

Instances

Instances details
FromJSON Key Source # 
Instance details

Defined in Network.GMail.Simple

readKeyFile :: FilePath -> IO Key Source #

Read the key file provided by Google Cloud. It throws a FailedToParseKey exception when the file fails to parse.

If you don't want to read it from a local file, you can use the FromJSON instance of Key to read it. The function readKeyFile is just a wrapper around that.

Session

data Session Source #

A session that can be used to send mails.

  • It may be reused.
  • Multiple threads can use it simultaneously.

newSession Source #

Arguments

:: Key

Google API key

-> MailAddress

Mail address of the sender

-> IO Session 

Create a new session for the given sender.

Mail

newtype MailAddress Source #

A mail address as text.

Constructors

MailAddress Text 

Instances

Instances details
IsString MailAddress Source # 
Instance details

Defined in Network.GMail.Simple

data Mail a Source #

Mail datatype.

Constructors

Mail 

Fields

Instances

Instances details
Functor Mail Source #

You can use fmap to map a function over the body of a mail.

Instance details

Defined in Network.GMail.Simple

Methods

fmap :: (a -> b) -> Mail a -> Mail b #

(<$) :: a -> Mail b -> Mail a #

sendMail :: ToMailBody a => Session -> Mail a -> IO () Source #

Send mail using a session. It might throw a FailedToSend exception.

In order for this to work, the user must have permissions for the https://www.googleapis.com/auth/gmail.send scope.

Mail body

class ToMailBody a where Source #

Class of types that can be used as mail body.

Methods

toMailBody :: a -> Text Source #

Textual representation of the mail body.

mailContentType :: proxy a -> MediaType Source #

Value for the Content-Type header.

Instances

Instances details
ToMailBody Html Source # 
Instance details

Defined in Network.GMail.Simple

ToMailBody Text Source # 
Instance details

Defined in Network.GMail.Simple

Exceptions

data GMailException Source #

Exceptions thrown by functions in this library.

Constructors

FailedToSend Value

A mail failed to be sent. The JSON value contains the error message as sent by Google.

FailedToParseKey String

A key file failed to parse. The string contains the parsing error.