diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cb8a9cf..df905ca 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -123,8 +123,8 @@ jobs: - name: Prepare App run: | - mv sendemail.exe sendemail_${{github.ref_name}}.exe - tar cvfz sendemail_${{github.ref_name}}.tar.gz sendemail_${{github.ref_name}}.exe + mv sendemail.exe sendemail-win_${{github.ref_name}}.exe + tar cvfz sendemail-win_${{github.ref_name}}.tar.gz sendemail-win_${{github.ref_name}}.exe ls -l -a - name: Attach Artifact to Release @@ -132,11 +132,44 @@ jobs: if: startsWith(github.ref, 'refs/tags/') with: files: | - sendemail_${{github.ref_name}}.tar.gz + sendemail-win_${{github.ref_name}}.tar.gz env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + publish-npm: + name: Publish to NPM registry + if: github.event.release.target_commitish == 'main' + needs: [lint-test-app, build-sea] + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - name: Checkout the repository + uses: actions/checkout@v6 + with: + ref: ${{ github.event.release.tag_name }} + + - name: Use NodeJS v24.11.0 + uses: actions/setup-node@v6 + with: + node-version: 24.11.0 + registry-url: https://registry.npmjs.org/ + + - name: Build distribution package + run: | + cd app + npm ci + npm run transpile + + - name: Publish package + run: | + chmod u+x app/scripts/npm-publish.sh + ./app/scripts/npm-publish.sh + cd app + npm publish --provenance --access public + docker-build-push: name: Build and Push Docker Image if: github.event.release.target_commitish == 'main' && vars.DOCKERHUB_USERNAME != '' diff --git a/README.md b/README.md index d9c9072..e9e3621 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,13 @@ -## send-email +## @weaponsforge/sendemail -NPM scripts, library and CLI for sending text and HTML emails using Gmail SMTP with Google OAuth2. +NPM library and CLI for sending text and HTML emails using Gmail SMTP with Google OAuth2. > [!TIP] -> - **Pre-compiled windows binaries**
-> Pre-compiled [windows binaries](#๏ธ-building-the-windows-executable-file) are available for download in the latest [Releases](https://github.com/weaponsforge/send-email/releases) download page. +> - **Node.js package**
+> A Node.js package is available at https://www.npmjs.com/package/@weaponsforge/sendemail +> +> - **Pre-compiled Windows binaries**
+> Pre-compiled [Windows binaries](#๏ธ-building-the-windows-executable-file) are available for download in the latest [Releases](https://github.com/weaponsforge/sendemail/releases) download page. > > - **Docker image**
> A Docker image is available at https://hub.docker.com/r/weaponsforge/sendemail @@ -35,17 +38,15 @@ NPM scripts, library and CLI for sending text and HTML emails using Gmail SMTP w npm: 10.9.2 ``` 3. Gmail Account - - Gmail email/password - - Optional: - - Google Cloud Platform project configured with [OAuth2](https://developers.google.com/workspace/guides/configure-oauth-consent) settings and [credentials](https://developers.google.com/workspace/guides/manage-credentials) - - Read on the Google [Gmail](https://developers.google.com/gmail/api/guides), [SMTP and OAuth2 Setup](https://github.com/weaponsforge/email-sender?tab=readme-ov-file#using-the-oauth-20-playground) sections for more information + - Google Cloud Platform project configured with [OAuth2](https://developers.google.com/workspace/guides/configure-oauth-consent) settings and [credentials](https://developers.google.com/workspace/guides/manage-credentials) + - Read on the Google [Gmail](https://developers.google.com/gmail/api/guides), [SMTP and OAuth2 Setup](https://github.com/weaponsforge/email-sender?tab=readme-ov-file#using-the-oauth-20-playground) sections for more information ### Core Libraries/Frameworks (Installed via npm) -1. [googleapis](https://www.npmjs.com/package/googleapis) `v171.4.0` -2. [nodemailer](https://www.npmjs.com/package/nodemailer) `v8.0.1` +1. [googleapis](https://www.npmjs.com/package/googleapis) `v171.4.0` - Manages Gmail token access +2. [nodemailer](https://www.npmjs.com/package/nodemailer) `v8.0.1` - Sends emails using various transport options 3. [typescript](https://www.npmjs.com/package/typescript) `v5.9.3` - Compile-time error checker 4. [tsx](https://www.npmjs.com/package/tsx) `v4.21.0` - Runs TS files in development mode 5. [vitest](https://www.npmjs.com/package/vitest) `v4.0.18` - Runs tests @@ -69,35 +70,35 @@ NPM scripts, library and CLI for sending text and HTML emails using Gmail SMTP w ``` 4. Send a **text email** using the CLI, eg. using Bash: ```bash - npm run send-email -- text \ + npm run sendemail -- text \ -s "You are Invited" \ -c "Birthday party in December" \ -r a@gmail.com,b@gmail.com,c@gmail.com ``` - > ๐Ÿ’ก **TIP:** Use `send-email:dev` to work on development mode without needing to run `"npm run transpile"` + > ๐Ÿ’ก **TIP:** Use `sendemail:dev` to work on development mode without needing to run `"npm run transpile"` 5. Send a **styled HTML email** using the CLI, eg. using Bash: ```bash - npm run send-email -- html \ + npm run sendemail -- html \ -s "Reading Materials" \ -c "Lorem ipsum dolor sit amet" "this is paragraph 1" "this is paragraph 2" \ -r test@gmail.com,one@gmail.com,two@gmail.com ``` - > ๐Ÿ’ก **TIP:** No transpilation needed with `"send-email:dev"` + > ๐Ÿ’ก **TIP:** No transpilation needed with `"sendemail:dev"` 6. Send **WYSIWYG** HTML content using the CLI, eg. using Bash:
_(Adjust `@/utils/config/sanitizeHtml.ts` to allow more styles.)_ ```bash - npm run send-email -- html \ + npm run sendemail -- html \ -s "WYSIWYG Email" \ -w "

Hello, World

" \ -r "tester@gmail.com" ``` - > ๐Ÿ’ก **TIP:** Development mode via `"send-email:dev"` skips transpilation + > ๐Ÿ’ก **TIP:** Development mode via `"sendemail:dev"` skips transpilation ## ๐Ÿ› ๏ธ Installation @@ -113,6 +114,9 @@ NPM scripts, library and CLI for sending text and HTML emails using Gmail SMTP w 4. Set up the environment variables. Create a `.env` file inside the **/app** directory with reference to the `.env.example` file. +
+ ๐Ÿ‘‰ Click to view the environment variable definitions + | Variable Name | Description | | --- | --- | | GOOGLE_USER_EMAIL | Your Google email that you've configured for Gmail SMTP and Google OAuth2. | @@ -121,6 +125,7 @@ NPM scripts, library and CLI for sending text and HTML emails using Gmail SMTP w | GOOGLE_REDIRECT_URI | Allowed Google API redirect URI. Its value is `https://developers.google.com/oauthplayground` by default. | | GOOGLE_REFRESH_TOKEN | The initial (or any) refresh token obtained from the [OAuthPlayground](https://developers.google.com/oauthplayground). | +
## ๐Ÿš€ Usage @@ -285,19 +290,19 @@ This script runs automatically after `"npm run transpile"`, copying the `"/app/s ### C. CLI ๐Ÿ’ป -### `npm run send-email` +### `npm run sendemail` Sends text and HTML emails using the command line interface (CLI) with transpiled JavaScript. > ๐Ÿ’ก **IMPORTANT:** > - This script requires running the `"npm run transpile"` script before usage. -> - If you want to run these without transpiling, append a `:dev` after the NPM script: `"npm run send-email:dev"` +> - If you want to run these without transpiling, append a `:dev` after the NPM script: `"npm run sendemail:dev"` #### CLI Usage -- To view the list of available commands: `npm run send-email help` +- To view the list of available commands: `npm run sendemail help` ```text - Usage: send-email [options] [command] + Usage: sendemail [options] [command] CLI for sending text and HTML emails using Gmail SMTP and Google OAuth2 @@ -313,19 +318,19 @@ Sends text and HTML emails using the command line interface (CLI) with transpile ``` - Append a double dash `--` to pass arguments to the CLI commands eg., (using Bash) ```bash - npm run send-email -- text \ + npm run sendemail -- text \ -s "You are Invited" \ -c "Birthday party in December" \ -r a@gmail.com,b@gmail.com,c@gmail.com ``` -- View available options for the **send-email text [options]** command. +- View available options for the **sendemail text [options]** command. ```bash # Usage options for the send "text" email command - npm run send-email help text + npm run sendemail help text ``` ```text - Usage: send-email text [options] + Usage: sendemail text [options] Send raw text email to one or multiple recipient/s @@ -337,14 +342,14 @@ Sends text and HTML emails using the command line interface (CLI) with transpile -h, --help display help for command ``` -- View available options for the **send-email html [options]** command. +- View available options for the **sendemail html [options]** command. ```bash # Usage options for the send "html" email command - npm run send-email help html + npm run sendemail help html ``` ```text - Usage: send-email html [options] + Usage: sendemail html [options] Send paragraphs of text or WYSIWYG content as styled HTML email to one or multiple recipient/s. @@ -358,12 +363,12 @@ Sends text and HTML emails using the command line interface (CLI) with transpile -h, --help display help for command ``` -### `npm run send-email:dev` +### `npm run sendemail:dev` - Sends an email using the command line interface (CLI) in development mode using TypeScript. - Append a double dash `--` to pass arguments to the CLI commands. -- Usage: view the `"npm run send-email"` script for more information. They share similar usage. - - > ๐Ÿ’ก **NOTE:** Append `:dev` in the script eg., `npm run send-email:dev` +- Usage: view the `"npm run sendemail"` script for more information. They share similar usage. + - > ๐Ÿ’ก **NOTE:** Append `:dev` in the script eg., `npm run sendemail:dev`
diff --git a/app/.dockerignore b/app/.dockerignore index bed693c..e7a3cd0 100644 --- a/app/.dockerignore +++ b/app/.dockerignore @@ -12,13 +12,17 @@ Dockerfile *.txt *.d.ts *.map +.env* *.json *.blob *.exe -.env* +*.md src/**/*.js __tests__/**/*.js +LICENSE +README.md + !package.json !package-lock.json !tsconfig.json diff --git a/app/.gitignore b/app/.gitignore index aba0362..64e73f5 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -12,7 +12,11 @@ build/ .env* *.blob *.exe +*.md src/**/*.js __tests__/**/*.js +LICENSE +README.md + !.env.example diff --git a/app/index.ts b/app/index.ts deleted file mode 100644 index 67b76cf..0000000 --- a/app/index.ts +++ /dev/null @@ -1 +0,0 @@ -console.log('entry point') diff --git a/app/package-lock.json b/app/package-lock.json index 612edda..923f6bf 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1,12 +1,12 @@ { - "name": "send-email", - "version": "1.2.1", + "name": "@weaponsforge/sendemail", + "version": "1.2.2", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "send-email", - "version": "1.2.1", + "name": "@weaponsforge/sendemail", + "version": "1.2.2", "license": "MIT", "dependencies": { "commander": "^14.0.3", @@ -18,7 +18,7 @@ "zod": "^3.24.2" }, "bin": { - "send-email": "dist/scripts/cli/send.js" + "sendemail": "dist/scripts/cli/send.js" }, "devDependencies": { "@eslint/js": "^10.0.1", @@ -2834,9 +2834,9 @@ } }, "node_modules/glob/node_modules/minimatch": { - "version": "9.0.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.6.tgz", - "integrity": "sha512-kQAVowdR33euIqeA0+VZTDqU+qo1IeVY+hrKYtZMio3Pg0P0vuh/kwRylLUddJhB6pf3q/botcOvRtx4IN1wqQ==", + "version": "9.0.7", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.7.tgz", + "integrity": "sha512-MOwgjc8tfrpn5QQEvjijjmDVtMw2oL88ugTevzxQnzRLm6l3fVEF2gzU0kYeYYKD8C66+IdGX6peJ4MyUlUnPg==", "license": "ISC", "dependencies": { "brace-expansion": "^5.0.2" @@ -2883,17 +2883,16 @@ } }, "node_modules/google-auth-library": { - "version": "10.5.0", - "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-10.5.0.tgz", - "integrity": "sha512-7ABviyMOlX5hIVD60YOfHw4/CxOfBhyduaYB+wbFWCWoni4N7SLcV46hrVRktuBbZjFC9ONyqamZITN7q3n32w==", + "version": "10.6.1", + "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-10.6.1.tgz", + "integrity": "sha512-5awwuLrzNol+pFDmKJd0dKtZ0fPLAtoA5p7YO4ODsDu6ONJUVqbYwvv8y2ZBO5MBNp9TJXigB19710kYpBPdtA==", "license": "Apache-2.0", "dependencies": { "base64-js": "^1.3.0", "ecdsa-sig-formatter": "^1.0.11", - "gaxios": "^7.0.0", - "gcp-metadata": "^8.0.0", - "google-logging-utils": "^1.0.0", - "gtoken": "^8.0.0", + "gaxios": "7.1.3", + "gcp-metadata": "8.1.2", + "google-logging-utils": "1.1.3", "jws": "^4.0.0" }, "engines": { @@ -2950,19 +2949,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/gtoken": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/gtoken/-/gtoken-8.0.0.tgz", - "integrity": "sha512-+CqsMbHPiSTdtSO14O51eMNlrp9N79gmeqmXeouJOhfucAedHw9noVe/n5uJk3tbKE6a+6ZCQg3RPhVhHByAIw==", - "license": "MIT", - "dependencies": { - "gaxios": "^7.0.0", - "jws": "^4.0.0" - }, - "engines": { - "node": ">=18" - } - }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -3422,9 +3408,9 @@ } }, "node_modules/minimatch": { - "version": "10.2.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.2.tgz", - "integrity": "sha512-+G4CpNBxa5MprY+04MbgOw1v7So6n5JY166pFi9KfYwT78fxScCeSNQSNzp6dpPSW2rONOps6Ocam1wFhCgoVw==", + "version": "10.2.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.3.tgz", + "integrity": "sha512-Rwi3pnapEqirPSbWbrZaa6N3nmqq4Xer/2XooiOKyV3q12ML06f7MOuc5DVH8ONZIFhwIYQ3yzPH4nt7iWHaTg==", "license": "BlueOak-1.0.0", "dependencies": { "brace-expansion": "^5.0.2" diff --git a/app/package.json b/app/package.json index 8a20c15..7ca3b61 100644 --- a/app/package.json +++ b/app/package.json @@ -1,15 +1,29 @@ { - "name": "send-email", - "version": "1.2.1", + "name": "@weaponsforge/sendemail", + "version": "1.2.2", "description": "Sends emails using Gmail SMTP with username/pw or Google OAuth2", "main": "dist/index.js", + "types": "./dist/index.d.ts", "type": "module", "engines": { "node": ">=24" }, "bin": { - "send-email": "./dist/scripts/cli/send.js" + "sendemail": "./dist/scripts/cli/send.js" }, + "exports": { + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } + }, + "files": [ + "dist", + "!dist/demo", + "!dist/scripts/build", + "README.md", + "LICENSE" + ], "scripts": { "dev": "vitest", "transpile": "tsc -p tsconfig.prod.json && tsc-alias && npm run copy:files", @@ -27,8 +41,8 @@ "docker:dev:win": "export CHOKIDAR_USEPOLLING=1 && export CHOKIDAR_INTERVAL=1000 && vitest", "docker:watch:win": "tsc -p tsconfig.json --watch --watchFile dynamicPriorityPolling --watchDirectory dynamicPriorityPolling", "docker:test:ui:win": "export CHOKIDAR_USEPOLLING=1 && export CHOKIDAR_INTERVAL=1000 && npm run docker:test:ui", - "send-email": "node ./dist/scripts/cli/send.js", - "send-email:dev": "tsx ./src/scripts/cli/send.ts" + "sendemail": "node ./dist/scripts/cli/send.js", + "sendemail:dev": "tsx ./src/scripts/cli/send.ts" }, "repository": { "type": "git", @@ -36,8 +50,10 @@ }, "keywords": [ "email", - "gmail", "smtp", + "gmail", + "cli", + "send-email", "oauth2" ], "author": "weaponsforge", diff --git a/app/scripts/npm-publish.sh b/app/scripts/npm-publish.sh new file mode 100644 index 0000000..1cba1ea --- /dev/null +++ b/app/scripts/npm-publish.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Copy community files +cp LICENSE app/ +cp docs/README_NPM.md app/README.md diff --git a/app/src/__tests__/cli.test.ts b/app/src/__tests__/cli.test.ts index 76e7934..1090ba9 100644 --- a/app/src/__tests__/cli.test.ts +++ b/app/src/__tests__/cli.test.ts @@ -11,7 +11,7 @@ describe('CLI test suite', () => { */ test('Sends a text email using CLI options', async () => { const { stdout } = await execa('npm', [ - 'run', 'send-email:dev', '--', + 'run', 'sendemail:dev', '--', 'text', '-s', 'Hello, World!', '-c', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit...', @@ -27,7 +27,7 @@ describe('CLI test suite', () => { test('Sends the default HTML email using CLI options', async () => { const correctEmailList = 'testor@gmail.com,abc@gmail.com' - const { stdout } = await $`npm run send-email:dev -- html + const { stdout } = await $`npm run sendemail:dev -- html -s ${'Default HTML Message'} -c ${'This is paragraph #1'} ${'This is paragraph #2'} ${'This is paragraph #3'} -r ${correctEmailList}` @@ -36,7 +36,7 @@ describe('CLI test suite', () => { }, MAX_TIMEOUT) test('Sends WYSIWYG body content in HTML email', async () => { - const { stdout } = await $`npm run send-email:dev -- html + const { stdout } = await $`npm run sendemail:dev -- html -r ${'abc@gmail.com'} -s ${'WYSIWYG Email Content Message'} -c ${'This is paragraph #1'} ${'This is paragraph #2'} ${'This is paragraph #3'} @@ -52,7 +52,7 @@ describe('CLI test suite', () => { // Email list should be comma-separated const incorrectEmailList = 'testor@gmail.com|abc@gmail.com' - const { stdout } = await $`npm run send-email:dev -- html + const { stdout } = await $`npm run sendemail:dev -- html -s ${'Default HTML Message'} -c ${'helloooo'} -r ${incorrectEmailList}` diff --git a/app/src/index.ts b/app/src/index.ts index a00c208..97b5bb5 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -3,5 +3,6 @@ export { EmailTransport, GmailOAuthClient, SchemaValidator, + buildHtml, send -} from '@/lib/index.js' +} from './lib/index.js' diff --git a/app/src/scripts/cli/lib/meta.ts b/app/src/scripts/cli/lib/meta.ts index ace0222..723fd46 100644 --- a/app/src/scripts/cli/lib/meta.ts +++ b/app/src/scripts/cli/lib/meta.ts @@ -1,7 +1,7 @@ // CLI metadata const CLI_META = { PROGRAM: { - NAME: 'send-email', + NAME: 'sendemail', DESCRIPTION: 'CLI for sending text and HTML emails using Gmail SMTP and Google OAuth2' }, CMD_SEND_TEXT: { diff --git a/docs/README_NPM.md b/docs/README_NPM.md new file mode 100644 index 0000000..fe4fb0a --- /dev/null +++ b/docs/README_NPM.md @@ -0,0 +1,159 @@ +## @weaponsforge/sendemail + +NPM library for sending text and HTML emails using Gmail SMTP with Google OAuth2. + +### CLI Available + +> - **Pre-compiled Windows binaries**
+> Pre-compiled [Windows binaries](https://github.com/weaponsforge/send-email?tab=readme-ov-file#%EF%B8%8F-building-the-windows-executable-file) are available for download in the latest [Releases](https://github.com/weaponsforge/send-email/releases) download page. +> +> - **Docker image**
+> A Docker image is available at https://hub.docker.com/r/weaponsforge/sendemail + +### Table of Contents + +- [Requirements](#-requirements) +- [Quickstart](#-quickstart) +- [Code Samples](#-code-samples) + +## ๐Ÿ“‹ Requirements + +
+๐Ÿ‘‰ Click to expand the list of requirements + +1. NodeJS LTS v24.11.0 or higher + ```text + Recommended: + node: 24.11.0 + npm: 10.9.2 + ``` +2. Gmail Account + - Google Cloud Platform project configured with [OAuth2](https://developers.google.com/workspace/guides/configure-oauth-consent) settings and [credentials](https://developers.google.com/workspace/guides/manage-credentials) + - Read on the Google [Gmail](https://developers.google.com/gmail/api/guides), [SMTP and OAuth2 Setup](https://github.com/weaponsforge/email-sender?tab=readme-ov-file#using-the-oauth-20-playground) sections for more information + +### Core Libraries/Frameworks + +(Installed via npm) + +1. [googleapis](https://www.npmjs.com/package/googleapis) `v171.4.0` - Manages Gmail token access +2. [nodemailer](https://www.npmjs.com/package/nodemailer) `v8.0.1` - Sends emails using various transport options +3. [commander](https://www.npmjs.com/package/commander) `v14.0.3` - CLI library +4. [sanitize-html](https://www.npmjs.com/package/sanitize-html) `v2.17.1` - Sanitizes WYSIWYG HTML input +5. [zod](https://www.npmjs.com/package/zod) `v3.24.2` - Run-time input validation +6. [ejs](https://www.npmjs.com/package/ejs) `v4.0.1` - Composes HTML with dynamic text content + +
+
+ +## ๐Ÿ†• Quickstart + +1. Install library. + ```bash + npm i @weaponsforge/sendemail + ``` + +2. Set up the environment variables. Create a `.env` file in your root project directory with the following: + +
+ ๐Ÿ‘‰ Click to view the environment variable definitions + + | Variable Name | Description | + | --- | --- | + | GOOGLE_USER_EMAIL | Your Google email that you've configured for Gmail SMTP and Google OAuth2. | + | GOOGLE_CLIENT_ID | Google OAuth2 client ID linked with your Google Cloud Platform project. | + | GOOGLE_CLIENT_SECRET | Google OAuth2 client secret associated with the `GOOGLE_CLIENT_ID`. | + | GOOGLE_REDIRECT_URI | Allowed Google API redirect URI. Its value is `https://developers.google.com/oauthplayground` by default. | + | GOOGLE_REFRESH_TOKEN | The initial (or any) refresh token obtained from the [OAuthPlayground](https://developers.google.com/oauthplayground).

Read on [Using the OAuth 2.0 Playground](https://github.com/weaponsforge/email-sender?tab=readme-ov-file#using-the-oauth-20-playground) for more information about generating a refresh token using the Google OAuth Playground.

_(โš ๏ธ **INFO:** This is an older note; some steps may vary this 2025)_
| + +
+
+ +3. Send emails programmatically via code. See the examples under the [Code Samples](#-code-samples) section for more information. + +
+ +## ๐Ÿงพ Code Samples + +### A. Send a Text-format Email + +```typescript +import { send } from '@weaponsforge/sendemail' + +const main = async () => { + await send({ + recipient: 'tester@gmail.com', + subject: 'Test Message', + content: 'How are you?' + }) +} + +main() +``` + +### B. Send an HTML-format Email + +```typescript +import { buildHtml, send } from '@weaponsforge/sendemail' + +const emails = ['tester@gmail.com', 'admin@gmail.com'] + +const main = async () => { + // Build the HTML email content + const emailContent = await buildHtml({ + content: ['Lorem ipsum dolor sit amet...', 'paragraph #2', 'paragraph #3'], + recipients: emails, + sender: process.env.GOOGLE_USER_EMAIL + }) + + // Send the email + await send({ + subject: 'Welcome Aboard!', + content: emailContent, + recipients: emails, + isHtml: true + }) +} + +main() +``` + +### C. Extend Classes + +These are classes that manage the email-sending processes and configurations. + +```typescript + +// Sends emails using a Nodemailer transporter +import { EmailSender } from '@weaponsforge/sendemail' + +// Initializes the Nodemailer transport with Google OAuth2 +import { EmailTransport } from '@weaponsforge/sendemail' + +// Manages API keys, methods and properties of the Google `OAuth2Client` +import { GmailOAuthClient } from '@weaponsforge/sendemail' + +// Wrapper around `ZodObject` and `ZodEffects` zod schemas +import { SchemaValidator } from '@weaponsforge/sendemail' + +// eg., extend (or override) the EmailSender class +class MyOAuthClient extends GmailOAuthClient { + sayHello (name = '') { + console.log(`Hello, ${name}!`) + } +} + +const client = new MyOAuthClient() + +const token = await client.getAccessToken() +client.sayHello('Tester') +``` + +## References + +- Gmail API [[1]](https://developers.google.com/gmail/api/guides) [[2]](https://github.com/googleapis/google-api-nodejs-client) +- Gmail Quickstart [[3]](https://developers.google.com/gmail/api/quickstart/js) +- AMP for Gmail [[4]](https://developers.google.com/gmail/ampemail) +- Google Workspace Guide [[5]](https://developers.google.com/workspace/guides/get-started) + +@weaponsforge
+20260225