-
-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/mailer #612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
scheidtdav
wants to merge
73
commits into
dev
Choose a base branch
from
feat/mailer
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat/mailer #612
Changes from all commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
35eeb87
feat: add draft for port of user registration to resource route
scheidtdav 42593f0
feat: partly implement refresh token
scheidtdav dcd635f
docs: simplify contributing and add info about api routes and shared …
scheidtdav be4ebed
feat(api): finalize user registration endpoint
scheidtdav b4b8421
fix(tests): get the tests to run be reconfiguring build steps
scheidtdav 8fbb075
docs(db): readd db setup and seed scripts with README info for it
scheidtdav 1de6e69
fix: wrong import of utils
scheidtdav 08f4405
refactor: remove leftover custom server stuff
scheidtdav 4a3f8e4
fix(tests): add missing refresh token table
scheidtdav 29d3034
fix(tests): reenable remaining tests for registration
scheidtdav d164738
fix(ci): remove playwright and use correct node version
scheidtdav 7566724
fix(ci): run the tests with a postgres container
scheidtdav 44894b4
feat(tests): add coverage report
scheidtdav 77b4cc9
fix(build): reorganize server modules to correctly split client/ server
scheidtdav 5612a5f
fix(build): miss an import
scheidtdav 2e335d5
fix(build): remove leftovers from custom server implementation
scheidtdav bbf5430
chore(deps): bump react-router dependencies
scheidtdav bf19c7e
chore(deps): update react-router
scheidtdav 7d91045
feat/user me api (#559)
scheidtdav a5699de
feat(api): add root route (#560)
scheidtdav 760914b
start
JerryVincent 81a1f9c
new commit
JerryVincent acf1770
tested docs
JerryVincent eedb806
added a route
JerryVincent a6245ea
Added API Docs
JerryVincent 4712c6a
modified
JerryVincent f63dc07
removed unsupported packages
JerryVincent 7741945
updated
JerryVincent 3b620a0
Modified
JerryVincent f51f518
script generation without using ts-node.
JerryVincent 5f7a6ef
modified
JerryVincent f9ecca4
Merge branch 'api-prod' into feat/user-registration-api
scheidtdav bd0e52e
fix: update package-lock.json
scheidtdav 31f793c
Updated (#575)
JerryVincent 511b94a
Removed duplicate Documentation section (#576)
JerryVincent 98617c3
Update README.md
JerryVincent 9492e13
Feat/api email and password (#561)
scheidtdav 8a721f7
feat/api auth (#562)
scheidtdav ef552e1
feat(api): boxes for user endpoints (#573)
scheidtdav 46e89cd
feat/api misc (#571)
scheidtdav fcf4b8d
Merge branch 'dev' into feat/user-registration-api
jona159 1bd97eb
feat(api): add route and test files
scheidtdav 46b0422
feat: add test code
scheidtdav 787b662
feat: add dummy sensors to devices and implement getting them back
scheidtdav 95acb53
Merge branch 'dev' into feat/api-boxes-sensors
scheidtdav eb84619
feat: prefer dev server in no production envs and hide dev in prod
scheidtdav 84f57ca
feat(docs): start adding docs to route
scheidtdav a232d6b
Merge branch 'dev' into feat/api-boxes-sensors
scheidtdav cf36b0a
feat: finish up to the point where we need measurements
scheidtdav 0a35d3b
fix: api routes without need for measurements
scheidtdav 89e8c04
fix: stats call
scheidtdav 9a8e679
fix: remaining tests
scheidtdav 32bdb9e
fix: frontend issue from changing the service implementation
scheidtdav 48968e1
feat: add react mail
scheidtdav ad6862f
feat: add nodemailer and setup for sending mails
scheidtdav 8ee41ee
feat: send password reset mails
scheidtdav f64d2f4
refactor: fix lint issues with mails
scheidtdav 60f5683
feat: implement email confirmation mail
scheidtdav 989bf66
feat: add mail for new users
scheidtdav 02879e7
Merge branch 'dev' into feat/mailer
scheidtdav b7aa7d3
fix: rewrite package lock
scheidtdav 8173dd2
Merge branch 'dev' into feat/mailer
scheidtdav 523108f
fix: rewrite package lock
scheidtdav 39b2b12
fix: packages
scheidtdav f25561b
feat: add email to new devices being created
scheidtdav 0916ebb
feat: send mail when email requested to change
scheidtdav 9da7fb6
feat: set email language properly
scheidtdav bebbfba
feat: implement base mail for all devices and migrate device specifics
scheidtdav 21bc58f
Merge branch 'dev' into feat/mailer
scheidtdav 0df03ab
fix: move ts-ignore
scheidtdav 9b4970a
fix: use example vars for test
scheidtdav 26f8656
feat: use ethereal.email for testing
scheidtdav 1998425
fix: remove conflicting test
scheidtdav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| import { render } from '@react-email/components' | ||
| import * as dotenv from 'dotenv' | ||
| import nodemailer from 'nodemailer' | ||
| import type SMTPTransport from 'nodemailer/lib/smtp-transport' | ||
| dotenv.config() | ||
|
|
||
| // Interface to load env variables | ||
| // Note these variables can possibly be undefined | ||
| // as someone could skip these varibales or not setup a .env file at all | ||
|
|
||
| /** | ||
| * Interface for our configuration. | ||
| * Note these variables can possibly be undefined, | ||
| * as varibales may be skipped or there is no .env file at all | ||
| */ | ||
| interface Config { | ||
| SMTP_HOST: string | undefined | ||
| SMTP_PORT: number | undefined | ||
| SMTP_SECURE: boolean | undefined | ||
| SMTP_USERNAME: string | undefined | ||
| SMTP_PASSWORD: string | undefined | ||
| } | ||
|
|
||
| /** | ||
| * Processes environment variables and | ||
| * builds a configuration object from it. | ||
| * @returns {Config} A mailer configuration | ||
| */ | ||
| const getConfig = (): Config => { | ||
| const config = { | ||
| SMTP_HOST: process.env.SMTP_HOST, | ||
| SMTP_PORT: process.env.SMTP_PORT | ||
| ? Number(process.env.SMTP_PORT) | ||
| : undefined, | ||
| SMTP_SECURE: process.env.SMTP_SECURE | ||
| ? Boolean(JSON.parse(process.env.SMTP_SECURE)) | ||
| : undefined, | ||
| SMTP_USERNAME: process.env.SMTP_USERNAME, | ||
| SMTP_PASSWORD: process.env.SMTP_PASSWORD, | ||
| } | ||
|
|
||
| // check the config for missing entries and throw an error if necessary | ||
| for (const [key, value] of Object.entries(config)) { | ||
| if (value === undefined) { | ||
| throw new Error(`Missing key ${key} in config.env`) | ||
| } | ||
| } | ||
|
|
||
| return config | ||
| } | ||
|
|
||
| const config = getConfig() | ||
|
|
||
| class OSEMTransporter { | ||
| private static _instance: nodemailer.Transporter | null = null | ||
| private constructor() {} | ||
| public static async getInstance(): Promise<nodemailer.Transporter> { | ||
| if (this._instance !== null) return this._instance | ||
|
|
||
| if (process.env.TEST) { | ||
| return await new Promise((resolve, reject) => { | ||
| nodemailer.createTestAccount((err, account) => { | ||
| if (err) reject(err) | ||
| else { | ||
| this._instance = nodemailer.createTransport({ | ||
| host: 'smtp.ethereal.email', | ||
| port: 587, | ||
| secure: false, | ||
| auth: { | ||
| user: account.user, | ||
| pass: account.pass, | ||
| }, | ||
| }) | ||
| resolve(this._instance) | ||
| } | ||
| }) | ||
| }) | ||
| } else { | ||
| const transportOptions: SMTPTransport.Options = { | ||
| host: config.SMTP_HOST, | ||
| port: config.SMTP_PORT, | ||
| secure: config.SMTP_SECURE, | ||
| } | ||
| if ( | ||
| config.SMTP_USERNAME !== 'ignored' && | ||
| config.SMTP_PASSWORD !== 'ignored' | ||
| ) { | ||
| transportOptions['auth'] = { | ||
| user: config.SMTP_USERNAME, | ||
| pass: config.SMTP_PASSWORD, | ||
| } | ||
| } | ||
| this._instance = nodemailer.createTransport(transportOptions) | ||
| return this._instance | ||
| } | ||
| } | ||
| } | ||
| void OSEMTransporter.getInstance() // eagerly initialize the transporter | ||
|
|
||
| export interface MailAttachment { | ||
| filename: string | ||
| content: string | ||
| } | ||
|
|
||
| export const sendMail = async (mailConfig: { | ||
| recipientAddress: string | ||
| recipientName?: string | ||
| subject?: string | ||
| body: React.ReactElement | ||
| attachments?: MailAttachment[] | ||
| }) => { | ||
| try { | ||
| const mailHtml = await render(mailConfig.body) | ||
|
|
||
| await ( | ||
| await OSEMTransporter.getInstance() | ||
| ).sendMail({ | ||
| from: '"openSenseMap 🌍" <[email protected]>', | ||
| to: mailConfig.recipientName | ||
| ? `"${mailConfig.recipientName}" <${mailConfig.recipientAddress}>` | ||
| : mailConfig.recipientAddress, | ||
| subject: mailConfig.subject ?? 'openSenseMap', | ||
| html: mailHtml, | ||
| attachments: mailConfig.attachments, | ||
| }) | ||
| } catch (err) { | ||
| console.error(err) | ||
| throw err | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is something missing here?