Skip to content

Commit

Permalink
tested prod version print output
Browse files Browse the repository at this point in the history
  • Loading branch information
NIDHI2023 committed Dec 19, 2024
1 parent b84907d commit 0ee08be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 32 deletions.
23 changes: 8 additions & 15 deletions src/scripts/email/wrapped-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ var dotenv = require("dotenv");
var wrapped_html_1 = require("./wrapped-html");
firebase_admin_1["default"].initializeApp({
credential: firebase_admin_1["default"].credential.applicationDefault(),
databaseURL: 'https://qmi-test.firebaseio.com'
databaseURL: 'https://queue-me-in-prod.firebaseio.com'
});
dotenv.config();
var resend = new resend_1.Resend(process.env.RESEND_API_KEY);
// DO NOT SEND TO ACTUAL PROD YET YOU HAVENT CHANGED SUBJECT LINE
/** Returns an array of email objects to send - should be at most 100 per day.
- totalEmails is a list of all the user emails to send to.
- batchSize should be 49 or less to maintain free emailing.
Expand All @@ -60,18 +59,19 @@ var createBatches = function (totalEmails, batchSize) {
while (i < totalEmails.length && emailObjs.length <= 100) {
emailObjs.push({
from: '[email protected]',
// make below the dti address or something cause recievers can see
// but dti will not see recievers
to: ['[email protected]'],
// This is the dti address because recievers can see, but dti will not see recievers.
to: ['[email protected]'],
bcc: totalEmails.slice(i, Math.min(i + batchSize, totalEmails.length)),
subject: 'Check Out Your QMI Wrapped! : batch ' + i,
subject: 'Check Out Your QMI Wrapped!',
html: wrapped_html_1.HTML
});
// eslint-disable-next-line no-console
// console.log("bcc list: " + totalEmails.slice(i, Math.min(i+batchSize, totalEmails.length)));
i += batchSize;
}
if (emailObjs.length === 100) {
// eslint-disable-next-line no-console
console.log("Reached email limit of 100 emails per day.");
console.log("Reached email limit of 100 emails per day, stopped at i=" + i + ", user " + totalEmails[i] + ". \n Continue from this user the next day.");
}
return emailObjs;
};
Expand Down Expand Up @@ -101,16 +101,9 @@ var createBatches = function (totalEmails, batchSize) {
_a.label = 3;
case 3:
_a.trys.push([3, 5, , 6]);
return [4 /*yield*/, resend.batch.send(createBatches(["[email protected]"], 49))];
return [4 /*yield*/, resend.batch.send(createBatches(userEmails, 49))];
case 4:
data = _a.sent();
// const data = await resend.emails.send({
// from: '[email protected]',
// to: ['[email protected]'],
// bcc: ['[email protected]'],
// subject: 'Check Out Your QMI Wrapped!',
// html: HTML
// });
// eslint-disable-next-line no-console
console.log("Emails have been sent!");
// eslint-disable-next-line no-console
Expand Down
27 changes: 10 additions & 17 deletions src/scripts/email/wrapped-email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import { HTML } from "./wrapped-html";

admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: 'https://qmi-test.firebaseio.com'
databaseURL: 'https://queue-me-in-prod.firebaseio.com'

});

dotenv.config();
const resend = new Resend(process.env.RESEND_API_KEY);

// DO NOT SEND TO ACTUAL PROD YET YOU HAVENT CHANGED SUBJECT LINE

/** Returns an array of email objects to send - should be at most 100 per day.
- totalEmails is a list of all the user emails to send to.
- batchSize should be 49 or less to maintain free emailing.
Expand All @@ -29,19 +27,21 @@ const createBatches = (totalEmails: string[], batchSize: number) => {
emailObjs.push(
{
from: '[email protected]',
// make below the dti address or something cause recievers can see
// but dti will not see recievers
to: ['[email protected]'],
// This is the dti address because recievers can see, but dti will not see recievers.
to: ['[email protected]'],
bcc: totalEmails.slice(i, Math.min(i+batchSize, totalEmails.length)),
subject: 'Check Out Your QMI Wrapped! : batch ' + i,
subject: 'Check Out Your QMI Wrapped!',
html: HTML
}
)
// eslint-disable-next-line no-console
// console.log("bcc list: " + totalEmails.slice(i, Math.min(i+batchSize, totalEmails.length)));
i+= batchSize;
}
if (emailObjs.length === 100) {
// eslint-disable-next-line no-console
console.log("Reached email limit of 100 emails per day.")
console.log(`Reached email limit of 100 emails per day, stopped at i=${i}, user ${totalEmails[i]}.
Continue from this user the next day.`)
}
return emailObjs;

Expand Down Expand Up @@ -69,15 +69,8 @@ const createBatches = (totalEmails: string[], batchSize: number) => {
try {
// ALT:
const data = await resend.batch.send(
createBatches(["[email protected]"], 49));

// const data = await resend.emails.send({
// from: '[email protected]',
// to: ['[email protected]'],
// bcc: ['[email protected]'],
// subject: 'Check Out Your QMI Wrapped!',
// html: HTML
// });
createBatches(userEmails, 49)
);
// eslint-disable-next-line no-console
console.log("Emails have been sent!");
// eslint-disable-next-line no-console
Expand Down

0 comments on commit 0ee08be

Please sign in to comment.