feat: allow user delete mail && notify when send access changed (#132)

This commit is contained in:
Dream Hunter
2024-04-15 23:19:05 +08:00
committed by GitHub
parent 50f04b2456
commit 00231e7ade
8 changed files with 80 additions and 5 deletions

View File

@@ -1,3 +1,5 @@
import { createMimeMessage } from "mimetext";
export const getDomains = (c) => {
if (!c.env.DOMAINS) {
return [];
@@ -45,3 +47,33 @@ export const getAdminPasswords = (c) => {
}
return c.env.ADMIN_PASSWORDS;
}
export const sendAdminInternalMail = async (c, toMail, subject, text) => {
try {
const msg = createMimeMessage();
msg.setSender({
name: "Admin",
addr: "admin@internal"
});
msg.setRecipient(toMail);
msg.setSubject(subject);
msg.addMessage({
contentType: 'text/plain',
data: text
});
const message_id = Math.random().toString(36).substring(2, 15);
const { success } = await c.env.DB.prepare(
`INSERT INTO raw_mails (source, address, raw, message_id) VALUES (?, ?, ?, ?)`
).bind(
"admin@internal", toMail, msg.asRaw(), message_id
).run();
if (!success) {
console.log(`Failed save message from admin@internal to ${toMail}`);
}
return success;
} catch (error) {
console.log("sendAdminInternalMail error", error);
return false;
}
};