mirror of https://github.com/msgbyte/tailchat
feat(cli): add smtp tools which help user positioning issue
parent
2d0a7eb0b8
commit
e357d2e1c5
@ -0,0 +1,44 @@
|
|||||||
|
import { CommandModule } from 'yargs';
|
||||||
|
import { config } from 'dotenv';
|
||||||
|
import inquirer from 'inquirer';
|
||||||
|
import nodemailer from 'nodemailer';
|
||||||
|
import { parseConnectionUrl } from 'nodemailer/lib/shared';
|
||||||
|
|
||||||
|
export const smtpCommand: CommandModule = {
|
||||||
|
command: 'smtp',
|
||||||
|
describe: 'SMTP Service',
|
||||||
|
builder: (yargs) =>
|
||||||
|
yargs
|
||||||
|
.command(
|
||||||
|
'verify',
|
||||||
|
'Verify smtp sender service',
|
||||||
|
(yargs) => {},
|
||||||
|
async (args) => {
|
||||||
|
config(); // 加载环境变量
|
||||||
|
|
||||||
|
const { uri } = await inquirer.prompt([
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
name: 'uri',
|
||||||
|
message: 'SMTP_URI',
|
||||||
|
default: process.env.SMTP_URI,
|
||||||
|
validate: (input) =>
|
||||||
|
typeof input === 'string' && input.length > 0,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const transporter = nodemailer.createTransport(
|
||||||
|
parseConnectionUrl(uri)
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const verify = await transporter.verify();
|
||||||
|
console.log('Verify Result:', verify);
|
||||||
|
} catch (err) {
|
||||||
|
console.log('Verify Failed:', String(err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.demandCommand(),
|
||||||
|
handler() {},
|
||||||
|
};
|
Loading…
Reference in New Issue