mirror of
https://github.com/beilunyang/moemail.git
synced 2026-08-28 19:36:38 +08:00
feat(cli): add send command
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
import { Command } from "commander";
|
||||||
|
import { api } from "../api.js";
|
||||||
|
import { log, printJson, printText } from "../output.js";
|
||||||
|
|
||||||
|
export function registerSendCommand(program: Command) {
|
||||||
|
program
|
||||||
|
.command("send")
|
||||||
|
.description("Send an email from a temporary address")
|
||||||
|
.requiredOption("--email-id <id>", "email ID to send from")
|
||||||
|
.requiredOption("--to <address>", "recipient email address")
|
||||||
|
.requiredOption("--subject <subject>", "email subject")
|
||||||
|
.requiredOption("--content <content>", "email body text")
|
||||||
|
.action(async (opts) => {
|
||||||
|
const json = program.opts().json;
|
||||||
|
try {
|
||||||
|
const result = (await api.sendEmail(opts.emailId, {
|
||||||
|
to: opts.to,
|
||||||
|
subject: opts.subject,
|
||||||
|
content: opts.content,
|
||||||
|
})) as any;
|
||||||
|
|
||||||
|
if (json) {
|
||||||
|
printJson({
|
||||||
|
success: true,
|
||||||
|
remainingEmails: result.remainingEmails,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
printText(`Email sent successfully. Remaining today: ${result.remainingEmails}`);
|
||||||
|
}
|
||||||
|
} catch (e: any) {
|
||||||
|
log(`Error: ${e.message}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import { registerListCommand } from "./commands/list.js";
|
|||||||
import { registerWaitCommand } from "./commands/wait.js";
|
import { registerWaitCommand } from "./commands/wait.js";
|
||||||
import { registerReadCommand } from "./commands/read.js";
|
import { registerReadCommand } from "./commands/read.js";
|
||||||
import { registerDeleteCommand } from "./commands/delete.js";
|
import { registerDeleteCommand } from "./commands/delete.js";
|
||||||
|
import { registerSendCommand } from "./commands/send.js";
|
||||||
|
|
||||||
const program = new Command();
|
const program = new Command();
|
||||||
|
|
||||||
@@ -21,5 +22,6 @@ registerListCommand(program);
|
|||||||
registerWaitCommand(program);
|
registerWaitCommand(program);
|
||||||
registerReadCommand(program);
|
registerReadCommand(program);
|
||||||
registerDeleteCommand(program);
|
registerDeleteCommand(program);
|
||||||
|
registerSendCommand(program);
|
||||||
|
|
||||||
program.parse();
|
program.parse();
|
||||||
|
|||||||
Reference in New Issue
Block a user