Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
GOOGLE_USER_EMAIL: ${{ secrets.GOOGLE_USER_EMAIL }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
GOOGLE_REDIRECT_URI: ${{ secrets.GOOGLE_REDIRECT_URI }}
GOOGLE_REFRESH_TOKEN: ${{ secrets.GOOGLE_REFRESH_TOKEN }}
steps:
- name: Checkout the repository
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ jobs:
GOOGLE_USER_EMAIL: ${{ secrets.GOOGLE_USER_EMAIL }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
GOOGLE_REDIRECT_URI: ${{ secrets.GOOGLE_REDIRECT_URI }}
GOOGLE_REFRESH_TOKEN: ${{ secrets.GOOGLE_REFRESH_TOKEN }}

steps:
Expand Down
10 changes: 4 additions & 6 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ All source code lives in the `/app` directory. Run all npm commands from `/app`.
GOOGLE_USER_EMAIL
GOOGLE_CLIENT_ID
GOOGLE_CLIENT_SECRET
GOOGLE_REDIRECT_URI # https://developers.google.com/oauthplayground
GOOGLE_REFRESH_TOKEN
```

Expand Down Expand Up @@ -63,27 +62,26 @@ EmailTransport (lib/email/transport.ts)
└── EmailSender (lib/email/sender.ts)
```

- **`GmailOAuthClient`** (`lib/google/oauth2client.ts`) — Manages Google OAuth2 credentials; validates env vars via Zod schema on instantiation. Accepts optional constructor params; falls back to env vars.
- **`EmailTransport`** — Base class; initializes Nodemailer transporter via `createTransport3LO()`, which fetches a fresh access token from `GmailOAuthClient` if one hasn't been pre-generated.
- **`EmailTransport`** — Base class; initializes Nodemailer transporter via `createTransport3LO(options?)`. Reads Google OAuth2 credentials from `options` fields, falling back to `GOOGLE_*` env vars. Nodemailer handles token refresh internally via the `refreshToken` field.
- **`EmailSender`** — Extends `EmailTransport`; exposes `sendEmail()` method; validates email params with Zod schema. Supports a single `recipient` string or a `recipients[]` array (max 20 total).
- **`SchemaValidator`** (`lib/validator/schemavalidator.ts`) — Generic Zod validation wrapper; handles both `ZodObject` and `ZodEffects` (`.refine()`) schemas; supports partial validation via `pick`.

### Key Data Flow

1. **Library usage**: `send()` (`lib/email/send.ts`) → creates `GmailOAuthClient` + `EmailSender` → `createTransport3LO()` → `sendEmail()`
1. **Library usage**: `send(params, oauth2?)` (`lib/email/send.ts`) → creates `EmailSender` → `createTransport3LO(oauth2?)` → `sendEmail()`
2. **CLI text**: Commander.js (`scripts/cli/send.ts`) → `handleSendTextEmail` → `send()`
3. **CLI HTML**: Commander.js → `handleSendHtmlEmail` → `buildHtml()` (renders EJS template, sanitizes HTML) → `send()` with `isHtml: true`
4. **SEA builds**: `build.ts` checks `IS_BUILD_SEA=true` to import the EJS template via `import()` (baked into the binary) rather than reading it from disk.

### Public API (`src/index.ts`)

Exports: `send`, `buildHtml`, `EmailSender`, `EmailTransport`, `GmailOAuthClient`, `SchemaValidator`, plus all types from `src/types/`.
Exports: `send`, `buildHtml`, `EmailSender`, `EmailTransport`, `SchemaValidator`, plus all types from `src/types/`.

### Validation

All input validation uses Zod schemas in `src/types/`:
- `email.schema.ts` — `EmailSchema` for `send()` params; `HtmlBuildSchema` for `buildHtml()` params; `EmailTextOptions` / `EmailHtmlOptions` interfaces for CLI handlers
- `oauth2client.schema.ts` — Google OAuth2 env vars
- `transport.schema.ts` — `TransportOath2Schema` / `TransportOath2SchemaType` for optional OAuth2 credentials passed to `send()` and `createTransport3LO()`

### ESM Compatibility

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ We welcome contributions! Please see [CONTRIBUTING.md](/CONTRIBUTING.md) and the
| 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).<ul><li>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.</li><li><blockquote>_(⚠️ **INFO:** This is an older note; some steps may vary this 2025)_</blockquote></li></ul> |

</details>
Expand Down
1 change: 0 additions & 1 deletion app/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
GOOGLE_USER_EMAIL=YOUR_GMAIL_OAUTH_EMAIL_HERE
GOOGLE_CLIENT_ID=YOUR_GOOGLE_PROJECT_CLIENT_ID_HERE
GOOGLE_CLIENT_SECRET=YOUR_GOOGLE_PROJECT_CLIENT_SECRET_HERE
GOOGLE_REDIRECT_URI=https://developers.google.com/oauthplayground
GOOGLE_REFRESH_TOKEN=ANY_REFRESH_TOKEN_GENERATED_FROM_OAUTHPLAYGROUND_HERE
Loading
Loading