-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom SMTP email server testing on the dashboard (#376)
- Loading branch information
1 parent
c1416ba
commit 534fef5
Showing
12 changed files
with
405 additions
and
78 deletions.
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.