Bỏ qua, tới nội dung chính

Kiến trúc · ADR 0064

ADR-0064: Outbound email through Resend's SMTP, starting with submission alerts

Trạng thái
Ngày
Người quyết định

Context

Course owners asked to hear by email, not only under the bell, when a student submits a project or essay. Production had no mail provider: SMTP_URL was unset, so even password-reset emails went to an Ethereal test inbox. The project now owns smartlearning.click.

Decision

  • Send from thongbao@smartlearning.click through Resend, using its SMTP endpoint behind the existing MailService (nodemailer). No SDK and no new code path: production sets SMTP_URL and MAIL_FROM; dev and tests keep Ethereal and the JSON transport.
  • A domain we control (DKIM, SPF, DMARC) beats a Gmail account with an app password for deliverability and for not tying the platform to someone's personal login.
  • One email per submission, sent by the API right after the in-app SUBMISSION_RECEIVED notice, fire and forget: never awaited, failures only logged. Missing one email is acceptable because the bell still has it; a slow SMTP server must never hold up a student's submit.
  • User.notifySubmissionEmail (default on) lets an owner turn the email off from their profile; the in-app notice is not affected.

Consequences

  • Password-reset emails start reaching real inboxes at the same time.
  • Resend's free tier (3,000 emails/month, 100/day) is far above a capstone class's volume. If it is ever exceeded, the email fails, is logged, and the bell still works.
  • A queue-backed sender (retries, digests) is deferred until volume or a second email type needs it.