Skip to content

Diya 🔥 fix(cron): Fixed Weekly Summary Cron#2159

Merged
one-community merged 1 commit intodevelopmentfrom
Diya_Fix_WeeklySummaryCron
Apr 9, 2026
Merged

Diya 🔥 fix(cron): Fixed Weekly Summary Cron#2159
one-community merged 1 commit intodevelopmentfrom
Diya_Fix_WeeklySummaryCron

Conversation

@DiyaWadhwani
Copy link
Copy Markdown
Contributor

Description

Fixes a bug where weekly summary cron job emails were failing to send due to Gmail's 552-5.3.4 header size limit. The Reply-To header was being set to a comma-separated string of all user emails (~34,000 bytes), exceeding Gmail's 32,768 byte per header limit. Additionally, refactored hardcoded email arrays across blue square cron jobs into a shared COMPANY_EMAILS constant.

Related PRs:

None

Main changes explained:

  • Added COMPANY_EMAILS constant in userHelper.js containing the two core org emails, to avoid repetition and make future updates easier
  • Updated emailWeeklySummariesForAllUsers to pass COMPANY_EMAILS as replyTo instead of the full emailString (all user emails), which was causing the Gmail header size error
  • Updated assignBlueSquareForTimeNotMet to use COMPANY_EMAILS instead of the inline hardcoded array for the cc field
  • Updated notifyInfringements to use COMPANY_EMAILS instead of the inline hardcoded array for the cc field, and removed the duplicate arguments that were being passed to emailSender

How to test:

  1. Check out the current branch
  2. Run npm install and start the server
  3. Trigger the weekly summaries cron job manually using the script below
const mongoose = require('mongoose');
require('dotenv').config();
const userHelperFactory = require('./userHelper');
async function main() {
  try {
    const mongoUri = process.env.MONGO_URI || process.env.MONGODB_URI;
    if (!mongoUri) {
      throw new Error('Missing MONGO_URI / MONGODB_URI in environment.');
    }
    await mongoose.connect(mongoUri, {
      maxPoolSize: 10,
      serverSelectionTimeoutMS: 30000,
      socketTimeoutMS: 45000,
    });
    console.log('✅ Connected to MongoDB');
    const userhelper = userHelperFactory();
    console.log('🚀 Running emailWeeklySummariesForAllUsers()...\n\n');
    await userhelper.emailWeeklySummariesForAllUsers();
    console.log('\n\n✅ emailWeeklySummariesForAllUsers() finished');
    await mongoose.disconnect();
    process.exit(0);
  } catch (err) {
    console.error('❌ Script failed:', err);
    process.exit(1);
  }
}
module.exports = { main };
if (require.main === module) {
  main()
    .then(() => {
      console.log('Script completed successfully');
      process.exit(0);
    })
    .catch((err) => {
      console.error('Script failed:', err);
      process.exit(1);
    });
}
  1. You can setup gmail oauth or just use logs to verify the difference in the reply-to addresses.
  2. Verify the Reply-To header on the received email shows the org emails, not a giant list of all users

Note:

The root cause of the email failure was emailString (a comma-separated list of all ~2000+ user emails) being passed as the replyTo argument to emailSender, which Nodemailer set directly as the Reply-To header value. Gmail rejects headers exceeding 32,768 bytes. The fix passes COMPANY_EMAILS (2 addresses) instead. The emailString list remains in the email body as intended for admin reference.

@one-community one-community changed the title Diya fix(cron): Fixed Weekly Summary Cron Diya 🔥 fix(cron): Fixed Weekly Summary Cron Apr 9, 2026
@one-community one-community merged commit 9a0aac2 into development Apr 9, 2026
2 checks passed
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 9, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants