Intermediate Reading #pull-requests #breaking-change #github #email-delivery

Reading PR Descriptions

5 exercises — read a realistic GitHub PR description with a breaking change note, test plan, and multiple issue references. Extract motivation, understand deployment requirements, and interpret design decisions.

Key sections in a PR description
  • Summary → what changed and the one-line rationale
  • Motivation → evidence of the problem (incidents, metrics, user reports)
  • Breaking Change → what will break and what must be done before deploying
  • How to Test → reproducible steps with expected results
  • Related Issues → "Closes #N" auto-closes the issue on merge
0 / 5 completed
1 / 5
🔄 Pull Request #1024 — Migrate email delivery to SendGrid
## Pull Request #1024 — Migrate email delivery to SendGrid

**Author:** @alex_backend  |  **Branch:** feature/sendgrid-migration → main
**Status:** Ready for Review  |  **Reviewers:** @dana_infra, @priya_r

---

### Summary

Replaces the in-house SMTP relay with SendGrid for all transactional email
delivery. The current relay has no retry logic, no delivery tracking, and has
caused two incidents of silent email loss in the past 60 days.

### Motivation

Incidents INC-0441 and INC-0449 were both caused by the SMTP relay silently
dropping emails when the downstream mail server was temporarily unreachable.
Users reported not receiving password-reset and payment-confirmation emails.
SendGrid provides automatic retries with exponential back-off, webhook delivery
events, and a dashboard for real-time delivery monitoring.

### Changes Made

- Added `SendGridEmailService` implementing the existing `IEmailService` interface
- Updated `config/mail.ts` to read `SENDGRID_API_KEY` from environment
- Replaced all direct calls to `SmtpEmailService` with dependency injection via
  the `EmailServiceProvider`
- Added end-to-end tests using SendGrid's sandbox mode (no real emails sent)

### Breaking Change

**Deployment note:** The environment variable `SMTP_HOST` is no longer read.
Deployers must add `SENDGRID_API_KEY` to the production `.env` before
deploying this PR, otherwise all email delivery will fail silently.

### How to Test

1. Add `SENDGRID_API_KEY=SG.test_key` and `SENDGRID_SANDBOX=true` to `.env`
2. Run `npm test -- --grep email` — all 14 email tests should pass
3. Trigger a password-reset flow in the staging environment
4. Verify delivery event appears in the SendGrid dashboard under Activity

### Screenshots

See attached: sendgrid-dashboard-activity.png (delivery event confirmed in sandbox)

### Related Issues

Closes #998 — Silent email loss with SMTP relay
Closes #1003 — Add delivery tracking for transactional email
What is the primary motivation for replacing the SMTP relay, according to the Motivation section?