diff --git a/tools/emails.txt b/tools/emails.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tools/promotional-emails.js b/tools/promotional-emails.js new file mode 100644 index 000000000..fa6be3529 --- /dev/null +++ b/tools/promotional-emails.js @@ -0,0 +1,73 @@ +const fs = require('fs'); +const path = require('path'); +const { Resend } = require('resend'); +require('dotenv').config(); + +const resend = new Resend( + process.env.RESEND_API_KEY_2 || + process.env.RESEND_API_KEY +); + +const BATCH_SIZE = 100; + +async function sendEmail(email) { + return resend.emails.send({ + from: process.env.EMAIL_FROM || 'urBackend ', + to: email, + subject: 'Try urBackend', + html: ` +

Hi there 👋

+ +

I'm building urBackend, an open-source backend platform that helps developers build APIs and backend services faster.

+ +

I'd love for you to try it out and share feedback.

+ +

+ + Try urBackend + +

+ +

Thanks!

+ ` + }); +} + +async function main() { + const emails = fs + .readFileSync( + path.join(__dirname, 'emails.txt'), + 'utf8' + ) + .split(/\r?\n/) + .map(e => e.trim()) + .filter(Boolean); + + const parsed = Number(process.argv[2]); + const batchSize = Number.isInteger(parsed) && parsed > 0 ? parsed : BATCH_SIZE; + const batch = emails.slice(0, Math.min(batchSize, emails.length)); + console.log(`Sending ${batch.length} emails...`); + + const redactEmail = (value) => { + const [local, domain] = String(value).split('@'); + if (!domain) return '***'; + return `${local?.slice(0, 2) || '**'}***@${domain}`; + }; + + for (const email of batch) { + try { + await sendEmail(email); + console.error(`✗ ${redactEmail(email)}`, err.message); + await new Promise(resolve => + setTimeout(resolve, 1000) + ); + + } catch (err) { + console.error(`✗ ${redactEmail(email)}`, err.message); + } + } + + console.log('Finished'); +} + +main(); \ No newline at end of file