44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import nodemailer from 'nodemailer';
|
|
import {WELCOME_EMAIL_TEMPLATE, NEWS_SUMMARY_EMAIL_TEMPLATE} from "@/lib/nodemailer/templates";
|
|
|
|
export const transporter = nodemailer.createTransport({
|
|
service: 'gmail',
|
|
auth: {
|
|
user: process.env.NODEMAILER_EMAIL!,
|
|
pass: process.env.NODEMAILER_PASSWORD!,
|
|
}
|
|
})
|
|
|
|
export const sendWelcomeEmail = async ({ email, name, intro }: WelcomeEmailData) => {
|
|
const htmlTemplate = WELCOME_EMAIL_TEMPLATE
|
|
.replace('{{name}}', name)
|
|
.replace('{{intro}}', intro);
|
|
|
|
const mailOptions = {
|
|
from: `"Openstock" <opendevsociety@gmail.com>`,
|
|
to: email,
|
|
subject: `Welcome to Openstock - your open-source stock market toolkit!`,
|
|
text: 'Thanks for joining Openstock, an initiative by open dev society',
|
|
html: htmlTemplate,
|
|
}
|
|
|
|
await transporter.sendMail(mailOptions);
|
|
}
|
|
|
|
export const sendNewsSummaryEmail = async (
|
|
{ email, date, newsContent }: { email: string; date: string; newsContent: string }
|
|
): Promise<void> => {
|
|
const htmlTemplate = NEWS_SUMMARY_EMAIL_TEMPLATE
|
|
.replace('{{date}}', date)
|
|
.replace('{{newsContent}}', newsContent);
|
|
|
|
const mailOptions = {
|
|
from: `"Openstock" <opendevsociety@gmail.com>`,
|
|
to: email,
|
|
subject: `📈 Market News Summary Today - ${date}`,
|
|
text: `Today's market news summary from Openstock`,
|
|
html: htmlTemplate,
|
|
};
|
|
|
|
await transporter.sendMail(mailOptions);
|
|
}; |