move environment to src/environment add smtp env vars, move some other items
Some checks failed
Code quality checks / biome (push) Failing after 13s
Some checks failed
Code quality checks / biome (push) Failing after 13s
This commit is contained in:
parent
421043c9b5
commit
00a7417936
30 changed files with 470 additions and 42 deletions
50
src/lib/validation/mailer.ts
Normal file
50
src/lib/validation/mailer.ts
Normal file
|
@ -0,0 +1,50 @@
|
|||
import { isValidEmail } from "./email";
|
||||
import { isValidHostname, isValidPort } from "./general";
|
||||
|
||||
import type { MailerConfig } from "#types/config";
|
||||
|
||||
function validateMailerConfig(config: MailerConfig): {
|
||||
isValid: boolean;
|
||||
errors: string[];
|
||||
} {
|
||||
const errors: string[] = [];
|
||||
|
||||
const isValidSMTPAddress = isValidHostname(config.address);
|
||||
|
||||
if (!isValidSMTPAddress) {
|
||||
errors.push(`Invalid SMTP address: ${config.address}`);
|
||||
}
|
||||
|
||||
if (!isValidPort(config.port)) {
|
||||
errors.push(
|
||||
`Invalid SMTP port: ${config.port}. Port must be between 1 and 65535`,
|
||||
);
|
||||
}
|
||||
|
||||
if (!isValidEmail(config.from)) {
|
||||
errors.push(`Invalid from email address: ${config.from}`);
|
||||
}
|
||||
|
||||
if (!isValidEmail(config.username)) {
|
||||
errors.push(`Invalid username email address: ${config.username}`);
|
||||
}
|
||||
|
||||
if (!config.password || config.password.trim().length === 0) {
|
||||
errors.push("SMTP password is required");
|
||||
}
|
||||
|
||||
if (config.port === 465 && !config.secure) {
|
||||
errors.push("Port 465 requires SMTP_SECURE=true");
|
||||
}
|
||||
|
||||
if (config.port === 587 && config.secure) {
|
||||
errors.push("Port 587 typically uses SMTP_SECURE=false with STARTTLS");
|
||||
}
|
||||
|
||||
return {
|
||||
isValid: errors.length === 0,
|
||||
errors,
|
||||
};
|
||||
}
|
||||
|
||||
export { isValidPort, isValidEmail, validateMailerConfig };
|
Loading…
Add table
Add a link
Reference in a new issue