Skip to content

Commit

Permalink
feat: add prefix for mail in sandbox (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitSerrano authored Dec 4, 2024
1 parent 3f75141 commit c61085c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion src/connectors/mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

//

Expand All @@ -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;
}

0 comments on commit c61085c

Please sign in to comment.