Files
headroom/frontend/node_modules/libphonenumber-js/build-scripts/helpers/sendEmail.js
Santhosh Janardhanan de2d83092e feat: Reinitialize frontend with SvelteKit and TypeScript
- Delete old Vite+Svelte frontend
- Initialize new SvelteKit project with TypeScript
- Configure Tailwind CSS v4 + DaisyUI
- Implement JWT authentication with auto-refresh
- Create login page with form validation (Zod)
- Add protected route guards
- Update Docker configuration for single-stage build
- Add E2E tests with Playwright (6/11 passing)
- Fix Svelte 5 reactivity with $state() runes

Known issues:
- 5 E2E tests failing (timing/async issues)
- Token refresh implementation needs debugging
- Validation error display timing
2026-02-17 16:19:59 -05:00

62 lines
2.0 KiB
JavaScript

import fs from 'fs'
import gmailSend from 'gmail-send'
export default async function sendEmail({ subject, text }) {
const emailSettings = getEmailSettings()
if (emailSettings) {
// Send an email notification through GMail.
//
// Example output:
//
// {
// result: '250 2.0.0 OK 1759154240 2adb3069b0e04-58313dd67c4sm4173572e87.55 - gsmtp',
// full: {
// accepted: [ 'kuchumovn@gmail.com' ],
// rejected: [],
// ehlo: [
// 'SIZE 35882577',
// '8BITMIME',
// 'AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH',
// 'ENHANCEDSTATUSCODES',
// 'PIPELINING',
// 'CHUNKING',
// 'SMTPUTF8'
// ],
// envelopeTime: 297,
// messageTime: 565,
// messageSize: 799,
// response: '250 2.0.0 OK 1759154240 2adb3069b0e04-58313dd67c4sm4173572e87.55 - gsmtp',
// envelope: { from: 'kuchumovn@gmail.com', to: [Array] },
// messageId: '<b7c49e37-1f0f-5c42-13c5-2398a778abd2@gmail.com>'
// }
// }
//
const { result, full } = await gmailSend({
user: emailSettings.email,
pass: emailSettings.accessToken,
to: emailSettings.email,
subject,
text
// html: '<b>html text</b>' // alternative to specifying `text`, one could specify `html`.
})()
return true
}
}
// Reads email settings from a JSON file just outside of `libphonenumber-js` repo folder.
function getEmailSettings() {
const emailSettingsPath = '../libphonenumber-js-autoupdate-email-notification-settings.json'
if (fs.existsSync(emailSettingsPath)) {
const emailSettings = JSON.parse(fs.readFileSync(emailSettingsPath, 'utf-8'))
// Validate `emailSettings`.
if (!emailSettings.email) {
throw new Error('`email` parameter not specified in the email config file')
}
// The instructions on how to obtain an `accessToken` are described in `gmail-send` readme:
// https://www.npmjs.com/package/gmail-send
if (!emailSettings.accessToken) {
throw new Error('`accessToken` parameter not specified in the email config file')
}
return emailSettings;
}
}