mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-07 13:11:49 +02:00
41 lines
1 KiB
TypeScript
41 lines
1 KiB
TypeScript
import nodemailer from "nodemailer";
|
|
import sgTransport from "nodemailer-sendgrid-transport";
|
|
|
|
interface SendEmailParameters {
|
|
to: string;
|
|
subject: string;
|
|
html: string;
|
|
}
|
|
|
|
const getTransport = async () => {
|
|
if (process.env.SENDGRID_API_KEY) {
|
|
const sgTransportParams = sgTransport({
|
|
auth: { api_key: process.env.SENDGRID_API_KEY },
|
|
});
|
|
return nodemailer.createTransport(sgTransportParams);
|
|
} else {
|
|
const auth = await nodemailer.createTestAccount();
|
|
|
|
console.log(
|
|
`Email sent using ethereal.email account:\n${auth.user}\n${auth.pass}`,
|
|
);
|
|
|
|
return nodemailer.createTransport({
|
|
host: "smtp.ethereal.email",
|
|
port: 587,
|
|
secure: false,
|
|
// In development we use https://ethereal.email
|
|
auth,
|
|
});
|
|
}
|
|
};
|
|
|
|
export const sendEmail = async (params: SendEmailParameters) => {
|
|
const transport = await getTransport();
|
|
return await transport.sendMail({
|
|
to: params.to,
|
|
from: `Rallly ${process.env.NEXT_PUBLIC_SUPPORT_EMAIL}`,
|
|
subject: params.subject,
|
|
html: params.html,
|
|
});
|
|
};
|