93 lines
4.4 KiB
JavaScript
93 lines
4.4 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Verify SMTP credentials and print the resolved From / Reply-To headers.
|
|
*
|
|
* From repo root:
|
|
* npm run phase-b:verify-smtp
|
|
*
|
|
* Optional test send (does not log the password):
|
|
* SMTP_TEST_TO=you@example.com npm run phase-b:verify-smtp
|
|
*/
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
const config_1 = require("../config");
|
|
const emailService_1 = require("../services/emailService");
|
|
async function main() {
|
|
console.log('Email transport:', config_1.config.email.transport);
|
|
if (config_1.config.email.transport !== 'smtp') {
|
|
console.error('SMTP is not active. Set EMAIL_TRANSPORT=smtp and SMTP_HOST, SMTP_USER, SMTP_PASS, EMAIL_FROM in .env');
|
|
process.exit(1);
|
|
}
|
|
if (!(0, emailService_1.isSmtpConfigured)()) {
|
|
console.error('Missing SMTP_HOST, SMTP_USER, SMTP_PASS, or EMAIL_FROM.');
|
|
process.exit(1);
|
|
}
|
|
const from = (0, emailService_1.resolveFromAddress)();
|
|
const replyTo = (0, emailService_1.resolveReplyToAddress)();
|
|
console.log('SMTP host:', config_1.config.email.host);
|
|
console.log('SMTP port:', config_1.config.email.port);
|
|
console.log('SMTP user (auth):', config_1.config.email.user);
|
|
console.log('EMAIL_FROM (env):', config_1.config.email.from);
|
|
console.log('Resolved From:', from);
|
|
console.log('Resolved Reply-To:', replyTo || '(none)');
|
|
await (0, emailService_1.verifySmtpConnection)();
|
|
console.log('SMTP connection OK — credentials accepted by the mail server.');
|
|
const testTo = (process.env.SMTP_TEST_TO || '').trim();
|
|
if (testTo) {
|
|
const transport = nodemailer_1.default.createTransport({
|
|
host: config_1.config.email.host,
|
|
port: config_1.config.email.port,
|
|
secure: config_1.config.email.port === 465 ? true : config_1.config.email.secure,
|
|
requireTLS: config_1.config.email.port === 587,
|
|
auth: {
|
|
user: config_1.config.email.user,
|
|
pass: (0, emailService_1.normalizeSmtpPass)(config_1.config.email.pass),
|
|
},
|
|
});
|
|
const info = await transport.sendMail({
|
|
from,
|
|
replyTo,
|
|
to: testTo,
|
|
subject: 'Tloto SMTP test',
|
|
text: [
|
|
'This is a test message from Tloto.',
|
|
`Auth user: ${config_1.config.email.user}`,
|
|
`From header: ${from}`,
|
|
`Reply-To: ${replyTo || '(none)'}`,
|
|
`Time: ${new Date().toISOString()}`,
|
|
].join('\n'),
|
|
});
|
|
console.log('Test message accepted by SMTP. messageId:', info.messageId);
|
|
console.log('Check the inbox for', testTo, '— From should show info@tloto.net (or your EMAIL_FROM).');
|
|
}
|
|
else {
|
|
console.log('Tip: set SMTP_TEST_TO=you@example.com to send a real test message.');
|
|
}
|
|
process.exit(0);
|
|
}
|
|
main().catch((e) => {
|
|
const msg = e instanceof Error ? e.message : String(e);
|
|
console.error('SMTP verification failed:', msg);
|
|
if (msg.includes('SmtpClientAuthentication is disabled') ||
|
|
msg.includes('smtp_auth_disabled')) {
|
|
console.error('\nMicrosoft 365 blocked SMTP AUTH for this tenant/mailbox.\n' +
|
|
' Enable Authenticated SMTP for admin@tloto.net (M365 admin → user → Mail → Email apps),\n' +
|
|
' or see https://aka.ms/smtp_auth_disabled — then retry verify-smtp.\n' +
|
|
' If MFA is on, use a Microsoft app password in SMTP_PASS.');
|
|
}
|
|
else if (msg.includes('535') || msg.includes('BadCredentials') || msg.includes('Authentication unsuccessful')) {
|
|
console.error('\nAuth rejected. Tloto uses Microsoft 365 / GoDaddy only (not Gmail):\n' +
|
|
' SMTP_HOST=smtp.office365.com SMTP_PORT=587 SMTP_SECURE=false\n' +
|
|
' SMTP_USER=admin@tloto.net (mailbox password or app password)\n' +
|
|
' EMAIL_FROM="Tloto <info@tloto.net>" (alias / Send As)\n' +
|
|
' EMAIL_REPLY_TO=info@tloto.net');
|
|
}
|
|
if (msg.includes('SendAsDenied') || msg.includes('not allowed to send') || msg.includes('550 5.7')) {
|
|
console.error('\nServer rejected From address. Grant “Send As” / confirm info@tloto.net is an alias of admin@tloto.net.');
|
|
}
|
|
process.exit(1);
|
|
});
|
|
//# sourceMappingURL=verifySmtp.js.map
|