# 3.4.2 Gmail

{% hint style="info" %}
This data source is not available in your deployments. You will not find it in your settings, please reach out to <support@ushahidi.com> or our chat messenger to enable it in your deployment.
{% endhint %}

This section allows you to set up the platform to receive and send emails through a connected Gmail account via the API. Before getting started, make sure that you have an email account set up on Gmail.\
\&#xNAN;***Note: If you're self hosting the Ushahidi platform, the Gmail Provider makes use of the server-side flow when making a request to Gmail API, and must be authorized using OAuth 2.0 Credentials.***

Follow this guide to create the OAuth 2.0 Credentials (Client ID and Client Secret) with [Gmail](https://support.google.com/googleapi/answer/6158849?hl=en). Keep in mind:

* Select "*where you will be calling the API from*" as Other UI.
* Select User data as the data type to be accessed.
* Select your application type as TVs and Limited Input devices.
* There's a need to set up a consent screen.

***

To ***get started with Gmail set up*** on the Ushahidi platform, click on Gmail from the drop down as shown below.

<figure><img src="https://1490970077-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGBEUb85x3qZ9AiwfCkhF%2Fuploads%2Fx3C4keNokhhCW5M15bDT%2F3.4.7.png?alt=media&#x26;token=fbafad1a-ac2e-4e99-adaf-518724b6398c" alt="List of available data sources - red arrow pointing to Gmail Data Source"><figcaption><p>List of available data sources - red arrow pointing to Gmail Data Source</p></figcaption></figure>

***Input the following email account settings***

* ***Email Address***: Enter the Gmail address you will be receiving and sending emails with.
* ***Fetch Email From***: Pick the date you want to start fetching messages from.
* ***Client Id***: Enter the Gmail client id gotten from the OAuth credentials.
* ***Client Secret***: Enter the Gmail client secret gotten from the OAuth credentials.
* ***Redirect URL***: Enter the redirect URL from the OAuth credentials. The default value set here is `urn:ietf:wg:oauth:2.0:oob` and in most cases should be left this way.&#x20;
* Click on ***Save*** and this data source’s settings will be saved.

***The below setup will be available to both the hosted and self-hosted users.***

* Next, Scroll up and click on ***Connect your Gmail Account*** and this will show a google prompt to authenticate your Gmail account.

<figure><img src="https://content.gitbook.com/content/GBEUb85x3qZ9AiwfCkhF/blobs/IXA3IlU3bWq30svfQwK4/gmail_connect.png" alt="Connect Your Gmail Account button displayed to prompt for authentication to your Gmail Account"><figcaption><p>Connect Your Gmail Account button displayed to prompt for authentication</p></figcaption></figure>

* Follow the prompt through and click on ***Allow*** to be presented with the list of Gmail accounts that you have.

<figure><img src="https://content.gitbook.com/content/GBEUb85x3qZ9AiwfCkhF/blobs/qSL9Xswpw8c3F0EFDZYb/Sign_in_-_Google_Accounts_and_Data_Sources_-_Ushahidi_-_Ushahidi_%F0%9F%94%8A.png" alt="External Gmail Authentication Page - Red arrow pointing to allow for ushahidi to access google account"><figcaption><p>External Gmail Authentication Page - Red arrow pointing to allow for ushahidi to access google account</p></figcaption></figure>

* Grant permission by selecting the Gmail account that you would like the Ushahidi platform to access.

<figure><img src="https://content.gitbook.com/content/GBEUb85x3qZ9AiwfCkhF/blobs/eMXr0l7SyAGD2ziLVqAt/Sign_in_-_Google_Accounts_and_Data_Sources_-_Ushahidi.png" alt="Choose An Account - Select an account from the list of Gmail accounts you have"><figcaption><p>Select an account from the list of Gmail accounts you have</p></figcaption></figure>

* This will display an auth code.
* Please copy the provided code, switch back to your Ushahidi application, and paste/enter it on the opened modal:
* Enter the point in time that you would like the Ushahidi platform to fetch messages from your inbox.

<figure><img src="https://content.gitbook.com/content/GBEUb85x3qZ9AiwfCkhF/blobs/NdzpkzjgvWrHXV9SFvrL/Data_Sources_-_Ushahidi_%F0%9F%94%8A.png" alt="Coonect Your Gmail Account Page - Enter Auth Code, Sync Date and then authorize or cancel"><figcaption><p>Coonect Your Gmail Account Page - Enter Auth Code, Sync Date and then authorize or cancel</p></figcaption></figure>

* Click on ***Authorize*** to save the auth code and date entered.
* A message will be displayed in your deployment to indicate that your ***account is connected,*** messages from Gmail will now be pulled into the platform via the API.
* To disconnect your account, simply click on ***Disconnect your Gmail account*** to stop all messages from being fetched from your inbox.

***NB: All messages that were previously fetched will not be deleted from your deployment.***

<figure><img src="https://content.gitbook.com/content/GBEUb85x3qZ9AiwfCkhF/blobs/lFdBBq8iSGFIlew0KWKW/Data_Sources_-_Ushahidi_-_Ushahidi.png" alt="Disconnect Your Gmail Account to stop all message from being fetched"><figcaption><p>Disconnect Your Gmail Account to stop all message from being fetched</p></figcaption></figure>

* To enable/disable the email data source, simply click on the green toggle and click on save.

<figure><img src="https://1490970077-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGBEUb85x3qZ9AiwfCkhF%2Fuploads%2F0ZAPrcOHAIGl1IsWMOSc%2F3.4.15.png?alt=media&#x26;token=fe64235f-4881-4791-befa-45f333adcd16" alt="Edit Gmail Data Source Page - Import to Basic Post highlighed."><figcaption><p>Edit Gmail Data Source Page - Import to Basic Post highlighted</p></figcaption></figure>
