Sends the site's email through the SMTP server of SMTPS_URL, which
may be unset. The welcome email, the password reset link and the digests go
through it, each rendered first by its module in api/mail/. They check
isEmailEnabled before rendering.
Importing this module throws when SMTPS_URL is set without FROM_EMAIL, so a misconfigured server doesn't start rather than fail at its first send.
Checks whether email can be sent. Without an SMTP server, sign-up sends no welcome email, a password reset request does nothing, and no digest goes out.
Sends email from FROM_EMAIL and resolves once the SMTP server has
accepted it. The welcome and reset emails don't wait for it: a slow server
mustn't hold up the request.
Replaces the transport, so that email is enabled and every message goes to
next; null disables email again. The tests use it to read what was sent.
Hands a message to a mail server. nodemailer's SMTP transport is one, and the tests put a recording one in its place with setEmailTransport.
Passed to sendEmail: a rendered email, its recipient, and the
headers some emails add (the digests' List-Unsubscribe).
Usage
import * as mod from "api/services/email-service.ts";