-
Notifications
You must be signed in to change notification settings - Fork 342
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
Added custom SMTP email server testing on the dashboard #376
Merged
+405
−78
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7658adc
added test email endpoint
fomalhautb ab5dcd1
added email error checking
fomalhautb 09399ff
added send test email form
fomalhautb 56dd28d
added test for email server edit
fomalhautb 8ff97d7
fixed ui bugs
fomalhautb 2d99e43
Merge branch 'dev' into test-email
fomalhautb 968dcaa
added toast
fomalhautb 822fadb
capture unknown error
fomalhautb 0f5e228
Update apps/dashboard/src/app/(main)/(protected)/projects/[projectId]…
fomalhautb b39fbed
Update apps/backend/src/lib/emails.tsx
fomalhautb de52102
Update apps/backend/src/lib/emails.tsx
fomalhautb 2b4e3a7
Update apps/backend/src/lib/emails.tsx
fomalhautb a76771d
Update apps/dashboard/src/app/(main)/(protected)/projects/[projectId]…
fomalhautb 5501690
renamed retryable
fomalhautb b6e7e09
merged duplicated type
fomalhautb 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 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 |
---|---|---|
|
@@ -15,6 +15,9 @@ | |
"Crudl", | ||
"ctsx", | ||
"deindent", | ||
"EAUTH", | ||
"EDNS", | ||
"EMESSAGE", | ||
"Falsey", | ||
"frontends", | ||
"geoip", | ||
|
This file contains 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
67 changes: 67 additions & 0 deletions
67
apps/backend/src/app/api/v1/internal/send-test-email/route.tsx
This file contains 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,67 @@ | ||
import { isSecureEmailPort, sendEmailWithKnownErrorTypes } from "@/lib/emails"; | ||
import { createSmartRouteHandler } from "@/route-handlers/smart-route-handler"; | ||
import * as schemaFields from "@stackframe/stack-shared/dist/schema-fields"; | ||
import { adaptSchema, adminAuthTypeSchema, emailSchema, yupBoolean, yupNumber, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields"; | ||
import { captureError } from "@stackframe/stack-shared/dist/utils/errors"; | ||
|
||
export const POST = createSmartRouteHandler({ | ||
metadata: { | ||
hidden: true, | ||
}, | ||
request: yupObject({ | ||
auth: yupObject({ | ||
type: adminAuthTypeSchema, | ||
project: adaptSchema.defined(), | ||
}).defined(), | ||
body: yupObject({ | ||
recipient_email: emailSchema.defined(), | ||
email_config: yupObject({ | ||
host: schemaFields.emailHostSchema.defined(), | ||
port: schemaFields.emailPortSchema.defined(), | ||
username: schemaFields.emailUsernameSchema.defined(), | ||
password: schemaFields.emailPasswordSchema.defined(), | ||
sender_name: schemaFields.emailSenderNameSchema.defined(), | ||
sender_email: schemaFields.emailSenderEmailSchema.defined(), | ||
}).defined(), | ||
}).defined(), | ||
method: yupString().oneOf(["POST"]).defined(), | ||
}), | ||
response: yupObject({ | ||
statusCode: yupNumber().oneOf([200]).defined(), | ||
bodyType: yupString().oneOf(["json"]).defined(), | ||
body: yupObject({ | ||
success: yupBoolean().defined(), | ||
error_message: yupString().optional(), | ||
}).defined(), | ||
}), | ||
handler: async ({ body }) => { | ||
const result = await sendEmailWithKnownErrorTypes({ | ||
emailConfig: { | ||
type: 'standard', | ||
host: body.email_config.host, | ||
port: body.email_config.port, | ||
username: body.email_config.username, | ||
password: body.email_config.password, | ||
senderEmail: body.email_config.sender_email, | ||
senderName: body.email_config.sender_name, | ||
secure: isSecureEmailPort(body.email_config.port), | ||
}, | ||
to: body.recipient_email, | ||
subject: "Test Email from Stack Auth", | ||
text: "This is a test email from Stack Auth. If you successfully received this email, your email server configuration is working correctly.", | ||
}); | ||
|
||
if (result.status === 'error' && result.error.errorType === 'UNKNOWN') { | ||
captureError("Unknown error sending test email", result.error); | ||
} | ||
|
||
return { | ||
statusCode: 200, | ||
bodyType: 'json', | ||
body: { | ||
success: result.status === 'ok', | ||
error_message: result.status === 'error' ? result.error.message : undefined, | ||
}, | ||
}; | ||
}, | ||
}); |
This file contains 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 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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
|
||
export type PrismaTransaction = Parameters<Parameters<PrismaClient['$transaction']>[0]>[0]; | ||
|
||
export type Prettify<T> = { | ||
[K in keyof T]: T[K]; | ||
} & {}; |
This file contains 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 |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
"export-to-csv": "^1.3.0", | ||
"geist": "^1", | ||
"jose": "^5.2.2", | ||
"lodash": "^4.17.21", | ||
"lucide-react": "^0.378.0", | ||
"next": "^14.2.5", | ||
"next-themes": "^0.2.1", | ||
|
@@ -61,6 +62,7 @@ | |
}, | ||
"devDependencies": { | ||
"@types/canvas-confetti": "^1.6.4", | ||
"@types/lodash": "^4.17.5", | ||
"@types/node": "^20.8.10", | ||
"@types/nodemailer": "^6.4.14", | ||
"@types/react": "link:@types/[email protected]", | ||
|
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.
you can't determine whether an SMTP server uses TLS or not just by the port (eg. it may be on a different port such as 587, 2525, 25025, etc). Also, 465 is not recommended anyways: https://www.mailgun.com/blog/email/which-smtp-port-understanding-ports-25-465-587/
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.
Should we add a setting in the DB for TLS?