Currently, the EmailService in the Rahat platform relies solely on Nodemailer for sending emails. To enhance flexibility and reliability, we need to refactor the service to support multiple email providers, making it pluggable. This will allow easy switching between providers such as SendGrid, Mailgun, and SMTP, depending on configuration or availability.
The new implementation should allow configuring multiple providers and dynamically selecting which one to use at runtime. This feature will increase resilience (failover to a secondary provider if one fails) and give us flexibility to integrate the best provider for a given use case.
Acceptance Criteria:
EmailService Refactor:
Refactor the current EmailService class located in apps/rahat/src/listeners/email.service.ts to allow for multiple email providers.
The service should be designed to plug in different email providers like Nodemailer, SendGrid, Mailgun, etc.
Provider Selection Logic:
Implement a mechanism to select the email provider dynamically based on configuration or fallback in case of failure.
Allow selecting the primary provider through environment variables (e.g., EMAIL_PROVIDER=nodemailer).
Fallback to secondary providers if the primary one fails, maintaining resilience in the email-sending process.
Provider Interface:
Create a unified EmailProvider interface that all email providers will implement. This interface should include methods for sending emails (sendMail).
Ensure each provider follows the EmailProvider interface and handles specific configurations (API keys, SMTP settings, etc.).
Documentation:
Update the README or internal documentation with details on how to configure and use different email providers, including environment variables and fallback behavior.
Currently, the EmailService in the Rahat platform relies solely on Nodemailer for sending emails. To enhance flexibility and reliability, we need to refactor the service to support multiple email providers, making it pluggable. This will allow easy switching between providers such as SendGrid, Mailgun, and SMTP, depending on configuration or availability.
The new implementation should allow configuring multiple providers and dynamically selecting which one to use at runtime. This feature will increase resilience (failover to a secondary provider if one fails) and give us flexibility to integrate the best provider for a given use case.
Acceptance Criteria:
EmailService Refactor:
EmailService
class located inapps/rahat/src/listeners/email.service.ts
to allow for multiple email providers.Provider Selection Logic:
EMAIL_PROVIDER=nodemailer
).Provider Interface:
sendMail
).Provider Implementations:
Documentation: