-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optional override for Postmark email From: field (#354)
This change allows an optional `POSTMARK_SENDER` env variable to be set alongside the existing `POSTMARK_TOKEN` in case the configure token's account is not approved for sending from the default (main/real) domain. Without this the "From: …" sender email address is hardcoded at quite a low-level which makes it difficult for code re-use. With this change, I'm enabled to set up a local environment and test from my *own* Postmark account without needing production keys. (Since I don't own or control the domain, sending an email from `[email protected]` gets rejected by the Postmark server with an error if requested via my own API token.) I have avoided touching most of the many places where environment variables are handled because most of those deal in terms of **required** env. This new config variable is optional: available for those who need it, but if not set, the email logic simply stays defaulted to what was the hardcoded sender. --------- Co-authored-by: Alan Shaw <[email protected]> Co-authored-by: Travis Vachon <[email protected]>
- Loading branch information
1 parent
99cbd2f
commit f6b2350
Showing
4 changed files
with
10 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,10 @@ export class Email { | |
* | ||
* @param {object} opts | ||
* @param {string} opts.token | ||
* @param {string} [opts.sender] | ||
*/ | ||
constructor(opts) { | ||
this.sender = opts.sender || 'web3.storage <[email protected]>' | ||
this.headers = { | ||
Accept: 'text/json', | ||
'Content-Type': 'text/json', | ||
|
@@ -22,7 +24,7 @@ export class Email { | |
method: 'POST', | ||
headers: this.headers, | ||
body: JSON.stringify({ | ||
From: 'web3.storage <[email protected]>', | ||
From: this.sender, | ||
To: opts.to, | ||
TemplateAlias: 'welcome', | ||
TemplateModel: { | ||
|
@@ -57,7 +59,7 @@ export class Email { | |
method: 'POST', | ||
headers: this.headers, | ||
body: JSON.stringify({ | ||
From: 'web3.storage <[email protected]>', | ||
From: this.sender, | ||
To: to, | ||
TextBody: textBody, | ||
Subject: subject, | ||
|