Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added tools/emails.txt
Empty file.
73 changes: 73 additions & 0 deletions tools/promotional-emails.js
Original file line number Diff line number Diff line change
@@ -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
);
Comment thread
yash-pouranik marked this conversation as resolved.

const BATCH_SIZE = 100;

async function sendEmail(email) {
return resend.emails.send({
from: process.env.EMAIL_FROM || 'urBackend <urbackend@apps.bitbros.in>',
to: email,
subject: 'Try urBackend',
html: `
<h2>Hi there 👋</h2>

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

<p>I'd love for you to try it out and share feedback.</p>

<p>
<a href="https://urbackend.bitbros.in">
Try urBackend
</a>
</p>

<p>Thanks!</p>
`
});
}

async function main() {
const emails = fs
.readFileSync(
path.join(__dirname, 'emails.txt'),
Comment thread
yash-pouranik marked this conversation as resolved.
'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();
Loading