fix(email): support attachments, and stop emailTestMode='false' swallowing every email - #11
Open
MaxAdams98 wants to merge 1 commit into
Open
MaxAdams98 wants to merge 1 commit into
MaxAdams98 wants to merge 1 commit into
Conversation
sendEmail had no way to attach a file, so an app that needs one has to bypass it and build the Mailgun message itself. It now takes `attachments` in nodemailer's shape and passes them through; the transport already maps them to Mailgun's attachment/inline fields, so nothing else changes. emailTestMode is nearly always populated from process.env, where every value is a string. `config.emailTestMode || test` therefore reads `emailTestMode=false` as true, and the app silently sends nothing while every call still resolves. The example app's config passes the raw env value, so this bites any project that writes the flag out in full rather than leaving it unset. The flag is now coerced, with the words that mean "off" spelled out. Also moves the `config` guard above its first use: sendEmail read config.emailTestMode before checking config existed, so a missing config threw a TypeError rather than the intended message.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two independent problems in
sendEmail, both found while building a monthly report that has to reach a governmentcontract manager with a signed PDF attached.
sendEmailcannot attach a fileThere is no way to pass one, so an app that needs an attachment has to bypass
sendEmailentirely and build theMailgun message itself, losing the template rendering, the recipient variables and the subject extraction.
nodemailer-mailgun-transportalready readsmail.attachmentsand maps it onto Mailgun'sattachment/inlinefields, so this is just a matter of passing the option through. The shape is nodemailer's, and an entry carrying a
cidis embedded inline rather than attached.emailTestMode=falsereads as true, and the app silently sends nothingconfig.emailTestModeis almost always populated fromprocess.env, where every value is a string, and theexample app's
server/config.jspasses it straight through:const isTest = config.emailTestMode || testthen treats the string'false'as true. The app stays in test mode,every
sendEmailcall resolves happily with the rendered HTML, and nothing is ever delivered. There is no error tonotice, which is what makes it worth fixing rather than documenting: an app that writes the flag out in full rather
than leaving it unset never sends an email and has no way to tell.
I hit this in production code that had been "sending" for weeks. The flag is now coerced, with the words that mean
off spelled out (
'',false,0,no,off); everything else keeps normal truthiness, so passing a real booleanbehaves exactly as before.
Also
config.emailTestModewas read one line beforeif (!config) throw, so callingsendEmailwithout a config threwa
TypeErrorinstead of the intended message. The guard now comes first.Verified
Patched into a real app's
node_modulesand exercised against it: the string'false'now falls through to thereal send path rather than being swallowed, and attachments reach the transport. Sending end to end is blocked only
by that project's Mailgun key, which is read-only.
Independent of #6, which touches different lines of the same file.