rahataid / rahat-platform

Rahat-Platform is a backend for Rahat, also known as Rahat core
https://docs.rahat.io
GNU Lesser General Public License v3.0
3 stars 13 forks source link

Enable `EmailService` to Use Multiple Email Providers (Pluggable Email Service) #148

Open myanzik opened 1 month ago

myanzik commented 1 month ago

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:

  1. 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.
  2. 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.
  3. Provider Interface:

    • Create a unified EmailProvider interface that all email providers will implement. This interface should include methods for sending emails (sendMail).
    • Example interface:
      interface EmailProvider {
      sendMail(to: string, subject: string, body: string): Promise<void>;
      }
  4. Provider Implementations:

    • Implement the following email providers:
      • Nodemailer (already integrated).
      • SendGrid.
      • Mailgun.
      • Custom Email Service.
    • Ensure each provider follows the EmailProvider interface and handles specific configurations (API keys, SMTP settings, etc.).
  5. Documentation:

    • Update the README or internal documentation with details on how to configure and use different email providers, including environment variables and fallback behavior.
Preet-taparia commented 1 month ago

hey, i would like to work on it, can you assign it to me?

myanzik commented 1 month ago

@Preet-taparia Sure. Let me know if there is any queries