mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-05 15:38:34 +08:00
feat: add resend for send mail (#275)
This commit is contained in:
@@ -86,7 +86,7 @@ const sendMailByResend = async (
|
|||||||
if (error) {
|
if (error) {
|
||||||
throw new Error(`Resend error: ${error.name} ${error.message}`);
|
throw new Error(`Resend error: ${error.name} ${error.message}`);
|
||||||
}
|
}
|
||||||
console.log(`Resend success: ${data}`);
|
console.log(`Resend success: ${JSON.stringify(data)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sendMailByMailChannels = async (
|
const sendMailByMailChannels = async (
|
||||||
@@ -193,13 +193,17 @@ export const sendMail = async (
|
|||||||
const resendEnabled = c.env.RESEND_TOKEN || c.env[
|
const resendEnabled = c.env.RESEND_TOKEN || c.env[
|
||||||
`RESEND_TOKEN_${mailDomain.replace(/\./g, "_").toUpperCase()}`
|
`RESEND_TOKEN_${mailDomain.replace(/\./g, "_").toUpperCase()}`
|
||||||
];
|
];
|
||||||
|
let sendByVerifiedAddressList = false;
|
||||||
if (c.env.SEND_MAIL) {
|
if (c.env.SEND_MAIL) {
|
||||||
const verifiedAddressList = await getJsonSetting(c, CONSTANTS.VERIFIED_ADDRESS_LIST_KEY) || [];
|
const verifiedAddressList = await getJsonSetting(c, CONSTANTS.VERIFIED_ADDRESS_LIST_KEY) || [];
|
||||||
if (verifiedAddressList.includes(to_mail)) {
|
if (verifiedAddressList.includes(to_mail)) {
|
||||||
await sendMailToVerifyAddress(c, address, reqJson);
|
await sendMailToVerifyAddress(c, address, reqJson);
|
||||||
return;
|
sendByVerifiedAddressList = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (sendByVerifiedAddressList) {
|
||||||
|
// do not update balance
|
||||||
|
}
|
||||||
// send by resend
|
// send by resend
|
||||||
else if (resendEnabled) {
|
else if (resendEnabled) {
|
||||||
await sendMailByResend(c, address, reqJson);
|
await sendMailByResend(c, address, reqJson);
|
||||||
@@ -209,15 +213,17 @@ export const sendMail = async (
|
|||||||
await sendMailByMailChannels(c, address, reqJson);
|
await sendMailByMailChannels(c, address, reqJson);
|
||||||
}
|
}
|
||||||
// update balance
|
// update balance
|
||||||
try {
|
if (!sendByVerifiedAddressList) {
|
||||||
const { success } = await c.env.DB.prepare(
|
try {
|
||||||
`UPDATE address_sender SET balance = balance - 1 where address = ?`
|
const { success } = await c.env.DB.prepare(
|
||||||
).bind(address).run();
|
`UPDATE address_sender SET balance = balance - 1 where address = ?`
|
||||||
if (!success) {
|
).bind(address).run();
|
||||||
|
if (!success) {
|
||||||
|
console.warn(`Failed to update balance for ${address}`);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
console.warn(`Failed to update balance for ${address}`);
|
console.warn(`Failed to update balance for ${address}`);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
console.warn(`Failed to update balance for ${address}`);
|
|
||||||
}
|
}
|
||||||
// save to sendbox
|
// save to sendbox
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user