Reference — Django Google Mailer 0.2.1 documentation

# Reference

## Gmail

class `gmailer.gmail.` `Gmail`(user, client_secrets_file, scopes, redirect_uri)

  This class defines all the core functional methods of Gmailer

  Parameters

    - user (str) – Admin user’s name which should appear to the end user who receive email

    - client_secrets_file (str) – Current state to be in

    - scopes (str) – Scopes which allow user to fetch data

    - redirect_uri (str) – Redirection URL for Google to use after verification

  Note

  You need to add GMAIL variables inside `settings.py` for proper initialisation of this class

  exception `SettingError`(message, error=None)

    When settings are not properly configured, this exception is raised

    Parameters

      - message (str) – Subject of the email send

      - error (`Exception`) – Body of the email send

  exception `StateError`(message, error=None)

    When state of the request is not matched with state from request, this exception is raised

    Parameters

      - message (str) – Subject of the email send

      - error (`Exception`) – Body of the email send

  exception `UnauthorizedAPIError`(message, error=None)

    When app try to access API without proper authorization, this exception is raised

    Parameters

      - message (str) – Subject of the email send

      - error (`Exception`) – Body of the email send

  `activated`

    A flag which indicate if Gmail API is authorized to be used

  `authorize`()

    Generate authorization url and state from `Flow` instance

    Returns

      A tuple of authorizationurl and state

  `flow`

    Store a `Flow` instance using client secret and scope list

  `revoke`()

    Revoke the data which is used by Gmail API to work

  `send_mail`(subject, message, recipient_list, html=False)

    Send email using Gmail API service

    Parameters

      - subject (str) – Subject of the email send

      - message (str) – Body of the email send

      - recipient_list (list) – A list of email addresses to send this email

      - html (bool) – If `True`, message created will be in HTML formate. Otherwise this message created will be plain text. Default is `False`

    Return type

      dict

  `test_mail`(subject=None, message=None, recipient_list=None)

    Send a test email using Gmail API service. If `recipient_list is` parameter not provided, mail is sent to sender itself.

    Parameters

      - subject (str) – Subject of the email send

      - message (str) – Body of the email send

      - recipient_list (list) – A list of email addresses to send this email

  `verify`(request)

    This method verify authorizated data and generate access token. It also generate a gmail api service as class property. It returns a dictionary of name, email id and credentials from `Flow` instance.

    Parameters

      request – A request object received from requested view

    Return type

      dict

## Views

`gmailer.views.` `auth`(request)

  Generate Google OAuth authorization url and state. State is stored inside session and view is redirected to the authorization url.

  Parameters

    request – A request object received from requested view

  Return type

    Redirection to authorization url

`gmailer.views.` `revoke`(request)

  Revoke the Google OAuth authorization.

  Parameters

    request – A request object received from requested view

  Return type

    `JsonResponse` instance

`gmailer.views.` `test_send_mail`(request)

  Test the Gmail API by sending an email to self.

  Parameters

    request – A request object received from requested view

  Return type

    `JsonResponse` instance

`gmailer.views.` `verify`(request)

  Verify code and state received from request.

  Parameters

    request – A request object received from requested view

  Return type

    `JsonResponse` instance

## Settings

### GMAIL_USER

Default: Django Mail Admin

This settings is the name of admin which shows up inside mail received by user

### GMAIL_SECRET

Default: google_client_secret.json

This settings is the name of admin which shows up inside mail received by user

### GMAIL_SCOPES

Default: [ https://www.googleapis.com/auth/gmail.metadata, https://www.googleapis.com/auth/gmail.send ]

This settings is the name of admin which shows up inside mail received by user

### GMAIL_REDIRECT

Default: http://localhost:8000/gmailer/verify

This settings is the name of admin which shows up inside mail received by user