feat(cli): add `smtp test` command which help user send test email full

pull/90/head
moonrailgun 2 years ago
parent a9ea4f50bb
commit 5bfa5b91bf

@ -1,6 +1,6 @@
{
"name": "tailchat-cli",
"version": "1.5.8",
"version": "1.5.9",
"description": "A Command line interface of tailchat",
"bin": {
"tailchat": "./bin/cli"

@ -16,14 +16,16 @@ export const smtpCommand: CommandModule = {
async (args) => {
config(); // 加载环境变量
console.log(
'This command will verify SMTP URI which use in tailchat, please put your URI which same like in tailchat env'
);
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,
validate: isValidStr,
},
]);
@ -39,6 +41,61 @@ export const smtpCommand: CommandModule = {
}
}
)
.command(
'test',
'Send test email with smtp service',
(yargs) => {},
async (args) => {
config(); // 加载环境变量
console.log(
'This command will send test email to your own email, please put your info which same like in tailchat env'
);
const { sender, uri, target } = await inquirer.prompt([
{
type: 'input',
name: 'sender',
message: 'SMTP_SENDER',
default: process.env.SMTP_SENDER,
validate: isValidStr,
},
{
type: 'input',
name: 'uri',
message: 'SMTP_URI',
default: process.env.SMTP_URI,
validate: isValidStr,
},
{
type: 'input',
name: 'target',
message: 'Email address which wanna send',
validate: isValidStr,
},
]);
const transporter = nodemailer.createTransport(
parseConnectionUrl(uri)
);
try {
const res = await transporter.sendMail({
from: sender,
to: target,
subject: `Test email send in ${new Date().toLocaleDateString()}`,
text: 'This is a test email send by tailchat-cli',
});
console.log('Send Result:', res);
} catch (err) {
console.log('Send Failed:', String(err));
}
}
)
.demandCommand(),
handler() {},
};
function isValidStr(input: any): boolean {
return typeof input === 'string' && input.length > 0;
}

Loading…
Cancel
Save