42 lines
1.9 KiB
JavaScript
42 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
// No app bootstrap, database access, dotenv loading, recipients, or sendMail.
|
|
// Runtime environment only. An explicit --verify is required for network access.
|
|
async function main() {
|
|
const args = process.argv.slice(2);
|
|
if (args.length === 1 && args[0] === '--help') {
|
|
console.log('Usage: node scripts/check-smtp.js --verify');
|
|
console.log('Checks SMTP DNS, connection, TLS and authentication only; sends no email.');
|
|
return;
|
|
}
|
|
if (args.length !== 1 || args[0] !== '--verify') {
|
|
console.error('Explicit --verify required. Use --help for usage.');
|
|
process.exitCode = 2;
|
|
return;
|
|
}
|
|
try {
|
|
require('reflect-metadata');
|
|
const { ConfigService } = require('@nestjs/config');
|
|
const configuration = require('../dist/apps/api-gateway/src/config/configuration').default;
|
|
const { validationSchema } = require('../dist/apps/api-gateway/src/config/validation.schema');
|
|
// Validate only email fields: this diagnostic needs no DB or JWT secrets.
|
|
for (const key of Object.keys(validationSchema.describe().keys).filter((key) => key.startsWith('EMAIL_'))) {
|
|
if (validationSchema.extract(key).validate(process.env[key]).error) {
|
|
console.error(`Invalid email environment variable: ${key}`);
|
|
process.exitCode = 2;
|
|
return;
|
|
}
|
|
}
|
|
const { EmailService } = require('../dist/apps/api-gateway/src/modules/email/email.service');
|
|
const service = new EmailService(new ConfigService(configuration()));
|
|
await service.verifySmtpConnection();
|
|
console.log('SMTP verification succeeded. No email sent; sender acceptance and delivery remain untested.');
|
|
} catch {
|
|
// EmailService logs allowlisted metadata. Never print an unexpected raw error.
|
|
console.error('SMTP diagnostic failed. Check safe EmailService diagnostics, EMAIL_* settings and compiled Gateway artifacts.');
|
|
process.exitCode = 1;
|
|
}
|
|
}
|
|
|
|
void main();
|