-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add prefix for mail in sandbox (#873)
- Loading branch information
1 parent
3f75141
commit c61085c
Showing
2 changed files
with
19 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
import { convert } from "html-to-text"; | ||
import { createTransport, type SendMailOptions } from "nodemailer"; | ||
import { SMTP_URL } from "../config/env"; | ||
import { DEPLOY_ENV, SMTP_URL } from "../config/env"; | ||
|
||
// | ||
|
||
|
@@ -17,12 +17,28 @@ interface SendMailBrevoOptions extends Omit<SendMailOptions, "from"> { | |
} | ||
export function sendMail(options: SendMailBrevoOptions) { | ||
const tag = options.tag ? [{ key: "X-Mailin-Tag", value: options.tag }] : []; | ||
const subject = computeMailSubject(options.subject); | ||
|
||
return transporter.sendMail({ | ||
text: | ||
typeof options.html === "string" ? convert(options.html) : options.text, | ||
headers: [...tag], | ||
...options, | ||
subject, | ||
from: "[email protected]", | ||
}); | ||
} | ||
|
||
function computeMailSubject( | ||
initialSubject: SendMailBrevoOptions["subject"], | ||
): SendMailBrevoOptions["subject"] { | ||
if (initialSubject === undefined) { | ||
return undefined; | ||
} | ||
|
||
if (DEPLOY_ENV === "sandbox") { | ||
return `Test - ${initialSubject}`; | ||
} | ||
|
||
return initialSubject; | ||
} |