-
-
Notifications
You must be signed in to change notification settings - Fork 40
Chaitanya - Mailchimp Replacement - Email Announcement System #1945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Conversation
…hments before sending email refactor(emailController): enhance email handling and subscription logic; improve error handling and HTML formatting feat(emailController): enhance email sending logic to support multiple recipients with BCC; improve response messages feat(routes): add email template router to API for enhanced email management feat(emailTemplateController): enhance getAllEmailTemplates with pagination, sorting, and field selection; add updated_by field to model feat(emailController, emailTemplateController): implement email batch processing for sending and managing emails feat(emailBatch): add retry functionality for failed batch items and update routes
…nce email batch auditing features - Added email announcement job processor to server initialization. - Introduced new audit trail endpoints in emailBatchController for tracking email and batch actions. - Updated email batch item status logic to reflect QUEUED state instead of PENDING. - Removed deprecated emailBatchDashboardController and related routes. - Enhanced email batch model to support comprehensive auditing and recipient management.
- Added EmailBatch and Email models for managing email batches and their recipients. - Introduced EmailBatchService and EmailService for handling batch creation, status updates, and email sending. - Implemented EmailProcessor for processing email batches with retry logic and status tracking. - Enhanced email announcement job processor to handle batch processing at scheduled intervals. - Updated email validation utilities for improved recipient handling and HTML content validation. - Added new endpoints in emailBatchController for managing email records and batch operations.
- Added permission checks for viewing emails, email details, and email audits in emailBatchController. - Implemented permission validation for sending emails, resending, and managing email subscriptions in emailController. - Updated emailTemplateController to enforce permission checks for creating, updating, and deleting email templates. - Refactored routes to replace deprecated sendEmailToAll with sendEmailToSubscribers. - Enhanced test cases to ensure proper handling of permission-related responses.
…zation - Removed redundant cron job initialization and logging from EmailAnnouncementJobProcessor. - Updated EmailProcessor to include additional final email status check for PROCESSED, enhancing email state validation.
…ions - Deleted the announcementEmailJob and associated configurations from emailJobConfig. - Removed emailBatchController and its routes, streamlining email processing logic. - Updated email models and services to reflect changes in email status management. - Refactored emailController to utilize new email processing methods and improved error handling. - Enhanced email validation utilities for better recipient management and HTML content checks.
…ling - Added functionality to process pending and stuck emails on server startup after database connection. - Updated email configuration to increase maximum recipients per request and refined batch processing settings. - Refactored email processing to queue emails for non-blocking, sequential handling instead of immediate processing. - Introduced new methods for managing stuck emails and batches, ensuring robust error handling and status updates. - Enhanced email validation utilities for better normalization of email fields.
…ervice - Updated emailController and emailTemplateController to utilize EmailTemplateService for template rendering and variable validation. - Introduced TEMPLATE_VARIABLE_TYPES in emailConfig for better management of variable types. - Removed the deprecated TemplateRenderingService, streamlining the email template handling process.
… management - Removed deprecated templateId from Email model to simplify email structure. - Updated email subscription list schema to enforce lowercase and trim email entries for consistency. - Introduced new methods for retrying failed emails and processing pending emails, improving error handling and user experience. - Enhanced email validation and normalization processes across controllers to ensure consistent data handling. - Refactored routes to improve clarity and organization of email-related endpoints.
- Enhanced validation for email subscriptions, including checks for missing or invalid email fields. - Improved error handling for subscription confirmation and removal processes, ensuring appropriate status codes are returned. - Updated positive test cases to reflect changes in subscription management and email normalization. - Removed deprecated sendEmailToAll functionality, streamlining email operations.
Anusha-Gali
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Chaitanya,
I have reviewed the PR locally and have mentioned by comments in the frontend PR: OneCommunityGlobal/HighestGoodNetworkApp#4492 (review) , in case any of them correlate to backend, please do recheck. Thank you
Hi @Anusha-Gali , Thanks for taking the time to test the feature. I have gone through your feedback. There is one issue that correlates with the backend - currently, our system do not have the ability to detect emails that are not delivered to recipients, as this needs additional operational complexity. This feature behaves exactly like how we send an email via Gmail/Outlook. If delivery fails, we will be notified later by Gmail, as shown in your screenshots (e.g., “Address not found”). It’s essentially a “spray and pray” approach. To provide more context, this is how the feature currently works:
Also, I verified that the retry/resend functionality works as expected from the backend perspective. However, it seems like there may be some misalignment between the frontend API endpoints and the API contract. |
VijayAnirudh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anusha-Gali
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Chaitanya,
I have re-reviewed your PR and left comments on frontend (mainly point 2 - i hope it is what you had explained to me in your previous comment) : OneCommunityGlobal/HighestGoodNetworkApp#4492 (review)

Description
This PR implements a comprehensive Email Announcement System for One Community to create, manage, and send email announcements to HGN users and external subscribers. The system includes reusable email templates with variable substitution, batch processing with retry logic, email outbox management.
Related PRs (if any):
To test this backend PR you need to checkout the #4492 frontend PR.
Frontend PR: OneCommunityGlobal/HighestGoodNetworkApp#4492
Main changes explained:
1. Email Template Management System
EmailTemplatemodel (src/models/emailTemplate.js) - Stores reusable email templates with:{{variableName}})EmailTemplateService(src/services/announcements/emails/emailTemplateService.js) - Provides:EmailTemplateController(src/controllers/emailTemplateController.js) - REST API endpoints:GET /api/email-templates- List all templates with search/sortGET /api/email-templates/:id- Get template by IDPOST /api/email-templates- Create new templatePUT /api/email-templates/:id- Update templateDELETE /api/email-templates/:id- Delete templatePOST /api/email-templates/:id/preview- Preview template with variables2. Email Announcement System
Emailmodel (src/models/email.js) - Parent record tracking:EmailBatchmodel (src/models/emailBatch.js) - Child records for batch processing:EmailService(src/services/announcements/emails/emailService.js) - Parent email management:EmailBatchService(src/services/announcements/emails/emailBatchService.js) - Batch processing:3. Email Sending Infrastructure
EmailSendingService(src/services/announcements/emails/emailSendingService.js) - SMTP integration:ANNOUNCEMENT_EMAIL_SENDER_NAME)EmailProcessor(src/services/announcements/emails/emailProcessor.js) - Queue-based processing:4. Email Management Controllers
EmailController(src/controllers/emailController.js) - Core email operations:POST /api/send-emails- Send email to specific recipients (max 2000)POST /api/broadcast-emails- Broadcast to all active HGN users and confirmed subscribersPOST /api/resend-email- Resend previously sent emailPOST /api/retry-email/:emailId- Retry failed email batchesPOST /api/process-pending-and-stuck-emails- Manual trigger for processingEmailOutboxController(src/controllers/emailOutboxController.js) - Outbox view:GET /api/emails- List all sent emailsGET /api/emails/:emailId- Get email details with batch status5. Configuration and Validation
emailConfig.js(src/config/emailConfig.js) - Centralized configuration:Key Features:
How to test:
Check into current branch
Run
npm installto install dependenciesEnsure required environment variables are set:
ANNOUNCEMENT_EMAIL- Gmail account email for sendingANNOUNCEMENT_EMAIL_SENDER_NAME- Sender display nameANNOUNCEMENT_EMAIL_CLIENT_ID- OAuth2 client IDANNOUNCEMENT_EMAIL_CLIENT_SECRET- OAuth2 client secretANNOUNCEMENT_EMAIL_CLIENT_REDIRECT_URI- OAuth2 redirect URIANNOUNCEMENT_EMAIL_REFRESH_TOKEN- OAuth2 refresh tokenRun
npm run devto start the backend serverFollow frontend PR steps to test the email announcement feature
Screenshots or videos of changes:
(Screenshots/videos would be provided by frontend PR #4492)
Note: