{"id":22341804,"url":"https://github.com/weaponsforge/email-sender","last_synced_at":"2026-04-05T20:33:41.810Z","repository":{"id":40565774,"uuid":"237759465","full_name":"weaponsforge/email-sender","owner":"weaponsforge","description":"Testing nodemailer for sending emails using gmail smtp and oauth2.","archived":false,"fork":false,"pushed_at":"2023-01-08T16:56:39.000Z","size":718,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2025-01-31T10:44:44.633Z","etag":null,"topics":["experiments","express","gmail-smtp","nodemailer","oauth2","react"],"latest_commit_sha":null,"homepage":"https://weaponsforge-emailsender.herokuapp.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weaponsforge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-02T11:17:41.000Z","updated_at":"2022-09-02T15:08:24.000Z","dependencies_parsed_at":"2023-02-08T06:46:02.108Z","dependency_job_id":null,"html_url":"https://github.com/weaponsforge/email-sender","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weaponsforge%2Femail-sender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weaponsforge%2Femail-sender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weaponsforge%2Femail-sender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weaponsforge%2Femail-sender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weaponsforge","download_url":"https://codeload.github.com/weaponsforge/email-sender/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245625238,"owners_count":20646120,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["experiments","express","gmail-smtp","nodemailer","oauth2","react"],"created_at":"2024-12-04T08:08:17.175Z","updated_at":"2025-12-30T23:24:42.576Z","avatar_url":"https://github.com/weaponsforge.png","language":"JavaScript","readme":"## email-sender\r\n\r\n\u003e Testing nodemailer with Google Gmail, SMTP and OAuth2 for sending emails.  \r\n\u003e Set-up OAuth 2.0 credentials (refresh token) from localhost.\r\n\r\n### Prerequisites\r\n\r\n1. Windows OS 64 bit\r\n2. NodeJS: the following versions were used for this demo\r\n\t- **node**: 10.16.3\r\n\t- **npm**: 6.9.0\r\n3. Gmail Account\r\n\t- [Google Cloud Platform](https://console.cloud.google.com/) project configured with OAuth2 settings and credentials\r\n\t- read on the [**Google Gmail, SMTP and OAuth2 Setup**](#using-a-local-oauth-20-generator) sections for more information\r\n\r\n### Content\r\n\r\n- [**Installation**](#installation)\r\n- [**Usage**](#usage)\r\n- **Google Gmail, SMTP and OAuth2 Setup**\r\n\t- [**Using a Local OAuth 2.0 Generator**](#using-a-local-oauth-20-generator)\r\n\t- [**Using the OAuth 2.0 Playground**](#using-the-oauth-20-playground)\r\n- [**References**](#references)\r\n\r\n\r\n## Installation\r\n\r\n1. Clone this repository.  \r\n`git clone https://github.com/weaponsforge/email-sender.git`\r\n\r\n2. Navigate into the project's root directory.\r\n\r\n3. Install dependencies.  \r\n`npm install`\r\n\r\n4. Source out the `.env.example` file to a `.env` file. Fill in the information with *your own* Google account credentials:\r\n\t- **EMAIL, CLIENT_USER**: your google email that you've configured for SMTP and OAuth2\r\n\t\t- read on the [**Using a Local OAuth 2.0 Generator**](#using-a-local-oauth-20-generator) section for more information\r\n\t- **CLIENT_ID**: Google Developer Project ID associated with your email\r\n\t\t- read on the [**Using a Local OAuth 2.0 Generator**](#using-a-local-oauth-20-generator) section, **#3 - #4** for more information on how to obtain this\r\n\t- **CLIENT_SECRET**: Client secret for the Google Developer Project CLIENT\\_ID\r\n\t- **REDIRECT_URI**: depending on your OAUth 2.0 setup, proceed to write as follows:\r\n\t\t- [**Using a Local OAuth 2.0 Generator**](#using-a-local-oauth-20-generator): urn:ietf:wg:oauth:2.0:oob\r\n\t\t- [**Using the OAuth 2.0 Playground**](#using-the-oauth-20-playground): *https://developers.google.com/oauthplayground*\r\n\t- **REFRESH_TOKEN**:\r\n\t\t- The initial (or any) refresh token obtained from [oauthplayground](https://developers.google.com/oauthplayground) or the [local oauth 2.0 generator](#using-a-local-oauth-20-generator)\r\n\t\t- read on [**Using a Local OAuth 2.0 Generator**](#using-a-local-oauth-20-generator) section, **#7** for more information on the how to obtain this. \r\n\t\t\t\u003e Take note that  [**Using a Local OAuth 2.0 Generator**](#using-a-local-oauth-20-generator) is the more recommended approach to obtain a refresh token, but you may also try [**Using the OAuth 2.0 Playground**](#using-the-oauth-20-playground).\r\n\r\n\r\n## Usage\r\n\r\n1. Navigate into the project's root directory.\r\n\r\n2. Start the server.  \r\n`npm run start`\r\n\r\n2. Build the jsx React components.  \r\n`npm run build`\r\n\r\n3. Load the app on: `http://localhost:3000`.\r\n\r\n4. Create new **jsx** components or edit existing from **/src/\\*.js**.  \r\n   - `npm run watch`\r\n   - refresh the website `http://localhost:3000`\r\n\r\n\r\n\r\n## Using a Local OAuth 2.0 Generator\r\n\r\nThe following methods are the more recommended approach to generate a **refresh token** since its steps are reproducible from your own server. You may also check out the previous-endorsed methods on [**Using the OAuth 2.0 Playground**](#using-the-oauth-20-playground).\r\n\r\n1. Create Project from the [Google Developer Console](https://console.cloud.google.com/). Use any project name.\r\n\r\n2. Configure the **OAuth Consent Screen**. (This can be found under **APIs and Services** side tab, or the **APIs** section on the project dahsboard.\r\n   - press the **Configure consent screen** button\r\n   - do not select anything for **User Type**\r\n   - Enter a value for **Application name**\r\n   - Save\r\n\r\n3. Press **Credentials** tab in the sidebar\r\n   - Press the **+CREATE CREDENTIALS** button\r\n   - select **OAuth client ID**\r\n   - select **Desktop app** for the type option. (This is named as \"**Other** in the past). Fill in the following:\r\n      - **Name**: *(any name for your project)*\r\n      - **Authorized redirect URIs**: `http://localhost:3000` *(or the server where you will run the local oauth 2.0 generator)*\r\n      - NOTE:  \r\n\t\t\t\u003e It is important that you select **\"Desktop app\"** for the type option.  \r\n\t\t\tThis is to display the generated `access_code` on the web browser for step **#8**.\r\n   - (OPTIONAL) select **Web Client** for the type option, instead of **Desktop app**. This is to ensure more security that the tokens exchange will only be used from your specified domain. Fill in the following:\r\n      - **Name**: *(any name for your project)*\r\n      - **Authorized redirect URIs**: `http://localhost:3000` *(or the server where you will run the local oauth 2.0 generator)*\r\n      - NOTE:  \r\n\t\t\t\u003e It is important that you select **\"Web Client\"** for the type option.  \r\n\t\t\tHowever, the `access_code` will not be displayed on the web browser on the proceeding step **#8**. Watch out for the value of the GET url parameter `code=\u003csome_value\u003e` from the url instead.\r\n   - press **Create**\r\n\r\n4. Save your **Client ID** and **Client Secret**. Download the JSON file that contains your full security credentials. Copy the value of the following in your **.env** file variables:\r\n\t- **CLIENT_ID**: `client_id` value\r\n\t- **CLIENT_SECRET**: `client_secret` value\r\n\t- **REDIRECT_URI**: `redirect_uris` value\r\n\t\t- select only the 1st item from the array.\r\n\t\t- Its default value is `urn:ietf:wg:oauth:2.0:oob` (if you chose **Desktop app** for the type option on step **#3**)\r\n\r\n5. Refer to `/server/oauthplayground.js` for more information on the actual **googleapis** code usage and set-up.\r\n\r\n6. Start the local server.  \r\n`npm run start`\r\n\r\n7. Load the local OAuth 2.0 generator.  \r\n`http://localhost:3000/oauthplayground`\r\n\r\n8. Configure **OAuth**. Get the refresh token from the local OAuth 2.0 generator.\r\n\t- Press the **Get Auth URL button**.\r\n\t\t- Launch the generated URL to another browser tab\r\n\t\t- Login your gmail account\r\n\t\t- You will be taken to a page that says \"This app isn't verified\"\r\n\t\t- press the **Advanced** link on the bottom left\r\n\t\t- press the link **Go to Your App’s Name (unsafe)**\r\n\t\t\t- A pop-up box that says \"Grant App Name permission\" will appear\r\n\t\t\t- select **Allow**\r\n\t\t\t- Copy and paste the `code` that will be displayed back to `http://localhost:3000/oauthplayground's` **code** field that says \"Enter code here\".\r\n\t\t\t- Press the **Get Access Token** button.\r\n    - Copy the generated code that will be displayed in the code input field to your refresh token variable in the **.env** file.  \r\n\t\t- **REFRESH_TOKEN**: *(generated code)*\r\n\r\n9. Restart the local server.\r\n\r\n\r\n## Using the OAuth 2.0 Playground\r\n\r\nThe following methods generates a **refresh token** using the [https://developers.google.com/oauthplayground](https://developers.google.com/oauthplayground).\r\n\r\n1. Create Project from the [Google Developer Console](https://console.cloud.google.com/). Use any project name.\r\n\r\n2. Configure the **OAuth Consent Screen**. (This can be found under **APIs and Services** side tab, or the **APIs** section on the project dahsboard.\r\n   - press the **Configure consent screen** button\r\n   - do not select anything for **User Type**\r\n   - Enter a value for **Application name**\r\n   - Save\r\n\r\n3. Press **Credentials** tab in the sidebar\r\n   - Press the **+CREATE CREDENTIALS** button\r\n   - select **OAuth client ID**\r\n   - select **Web application**. Fill in the following:\r\n      - **Name**: *(any name for your project)*\r\n      - **Authorized redirect URIs**: `https://developers.google.com/oauthplayground`\r\n   - press **Create**\r\n\r\n4. Save your **Client ID** and **Client Secret**.\r\n\r\n5. Configure **OAuth**. Get the refresh token.\r\n   - Go to [https://developers.google.com/oauthplayground](https://developers.google.com/oauthplayground)\r\n   - click the tools icon on the top right\r\n   - check the box that says **Use your own OAuth credentials**\r\n      - enter your OAuth **Client ID** and **Secret**\r\n   - Do not close the tool box from previous step yet\r\n      - enter `https://mail.google.com/` in the input field under **Select \u0026 authorize APIs**\r\n      - press the **Authorize APIs** button\r\n      - Login your gmail account\r\n      - You will be taken to a page that says \"This app isn't verified\"\r\n      - press the **Advanced** link on the bottom left\r\n      - press the link **Go to Your App’s Name (unsafe)**\r\n      - A pop-up box that says \"Grant App Name permission\" will appear\r\n         - select **Allow**\r\n         - you will be taken back to the OAuth page\r\n    - Go to \"Step 2: Exchange authorization code for tokens\" from the side bar\r\n       - press the **Exchange authorization code for tokens** button\r\n    - Copy the **Refresh Token** to your refresh token variable in the **.env** file.  \r\n\t\t- **REFRESH_TOKEN**: *(generated code)*\r\n\r\n6. Start the server.\r\n\r\n\r\n## References\r\n\r\n[[1]](https://medium.com/@nickroach_50526/sending-emails-with-node-js-using-smtp-gmail-and-oauth2-316fe9c790a1), [[2]](https://designdigitalsolutions.com/sending-mail-via-nodemailer-using-your-gmail-with-oauth2/) - sending email with nodejs using smtp, gmail and oauth2  \r\n[[3]](https://designdigitalsolutions.com/sending-mail-via-nodemailer-using-your-gmail-with-oauth2/) - Oauth 2.0 setup on localhost  \r\n[[4]](https://developers.google.com/identity/protocols/googlescopes) - OAuth 2.0 Scopes for Google APIs  \r\n[[5]](https://myaccount.google.com/permissions) - google account app permissions  \r\n[[6]](https://nodemailer.com/smtp/oauth2/) - nodemailer smtp oauth2  \r\n[[7]](https://trello.com/c/bClKZYX9) - trello notes\r\n\r\n@weaponsforge  \r\n20200202\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweaponsforge%2Femail-sender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweaponsforge%2Femail-sender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweaponsforge%2Femail-sender/lists"}