google.mail
#
Description#
GMail plugin. It allows you to programmatically compose and (TODO) get emails.
To use this plugin:
Create your Google application, if you don’t have one already, on the developers console.
You may have to explicitly enable your user to use the app if the app is created in test mode. Go to “OAuth consent screen” and add your user’s email address to the list of authorized users.
Select the scopes that you want to enable for your application, depending on the integrations that you want to use. See https://developers.google.com/identity/protocols/oauth2/scopes for a list of the available scopes.
Click on “Credentials”, then “Create credentials” -> “OAuth client ID”.
Select “Desktop app”, enter whichever name you like, and click “Create”.
Click on the “Download JSON” icon next to your newly created client ID. Save the JSON file under
<WORKDIR>/credentials/google/client_secret.json
.If you’re running the service on a desktop environment, then you can just start the application. A browser window will open and you’ll be asked to authorize the application - you may be prompted with a warning because you are running a personal and potentially unverified application. After authorizing the application, the process will save the credentials under
<WORKDIR>/credentials/google/<list,of,scopes>.json
and proceed with the plugin initialization.If you’re running the service on a headless environment, or you prefer to manually generate the credentials file before copying to another machine, you can run the following command:
mkdir -p <WORKDIR>/credentials/google python -m platypush.plugins.google.credentials \ 'gmail.modify' \ <WORKDIR>/credentials/google/client_secret.json [--noauth_local_webserver]When launched with
--noauth_local_webserver
, the script will start a local webserver and print a URL that should be opened in your browser. After authorizing the application, you may be prompted with a code that you should copy and paste back to the script. Otherwise, if you’re running the script on a desktop, a browser window will be opened automatically.
- param scopes:
List of scopes required by the API. See https://developers.google.com/identity/protocols/oauth2/scopes for a list of the available scopes. Override it in your configuration only if you need specific scopes that aren’t normally required by the plugin.
- param secrets_path:
Path to the client secrets file. You can create your secrets.json from https://console.developers.google.com. Default:
<PLATYPUSH_WORKDIR>/credentials/google/client_secret.json
.
Configuration#
google.mail:
# [Optional]
# List of scopes required by the API.
# See https://developers.google.com/identity/protocols/oauth2/scopes
# for a list of the available scopes. Override it in your configuration
# only if you need specific scopes that aren't normally required by the
# plugin.
# scopes: # type=Optional[Collection[str]]
# [Optional]
# Path to the client secrets file.
# You can create your secrets.json from https://console.developers.google.com.
# Default: ``<PLATYPUSH_WORKDIR>/credentials/google/client_secret.json``.
# secrets_path: # type=Optional[str]
Dependencies#
pip
pip install google-auth httplib2 oauth2client google-api-python-client
Alpine
apk add py3-google-auth py3-google-api-python-client py3-oauth2client py3-httplib2
Debian
apt install python3-google-auth python3-oauth2client python3-httplib2
Fedora
yum install python-google-api-client python-oauth2client python-httplib2 python-google-auth
Arch Linux
pacman -S python-google-api-python-client python-oauth2client python-httplib2 python-google-auth
Actions#
Module reference#
- class platypush.plugins.google.mail.GoogleMailPlugin(*args, **kwargs)[source]#
Bases:
GooglePlugin
GMail plugin. It allows you to programmatically compose and (TODO) get emails.
To use this plugin:
Create your Google application, if you don’t have one already, on the developers console.
You may have to explicitly enable your user to use the app if the app is created in test mode. Go to “OAuth consent screen” and add your user’s email address to the list of authorized users.
Select the scopes that you want to enable for your application, depending on the integrations that you want to use. See https://developers.google.com/identity/protocols/oauth2/scopes for a list of the available scopes.
Click on “Credentials”, then “Create credentials” -> “OAuth client ID”.
Select “Desktop app”, enter whichever name you like, and click “Create”.
Click on the “Download JSON” icon next to your newly created client ID. Save the JSON file under
<WORKDIR>/credentials/google/client_secret.json
.If you’re running the service on a desktop environment, then you can just start the application. A browser window will open and you’ll be asked to authorize the application - you may be prompted with a warning because you are running a personal and potentially unverified application. After authorizing the application, the process will save the credentials under
<WORKDIR>/credentials/google/<list,of,scopes>.json
and proceed with the plugin initialization.If you’re running the service on a headless environment, or you prefer to manually generate the credentials file before copying to another machine, you can run the following command:
mkdir -p <WORKDIR>/credentials/google python -m platypush.plugins.google.credentials \ 'gmail.modify' \ <WORKDIR>/credentials/google/client_secret.json [--noauth_local_webserver]
When launched with
--noauth_local_webserver
, the script will start a local webserver and print a URL that should be opened in your browser. After authorizing the application, you may be prompted with a code that you should copy and paste back to the script. Otherwise, if you’re running the script on a desktop, a browser window will be opened automatically.
- __init__(*args, **kwargs)[source]#
- Parameters:
scopes – List of scopes required by the API. See https://developers.google.com/identity/protocols/oauth2/scopes for a list of the available scopes. Override it in your configuration only if you need specific scopes that aren’t normally required by the plugin.
secrets_path – Path to the client secrets file. You can create your secrets.json from https://console.developers.google.com. Default:
<PLATYPUSH_WORKDIR>/credentials/google/client_secret.json
.