Skip to content

Commit

Permalink
Add utility function for sending email.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Oct 11, 2024
1 parent 398559b commit 8cf24a1
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions src/email.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
// import nodemailer from "nodemailer";
import nodemailer, { SendMailOptions } from "nodemailer";
import dotenv from "dotenv";

// const transporter = nodemailer.createTransport({
// host: "smtp.gmail.com",
// port: 587,
// secure: false,
// auth: {
// user: "[email protected]",
// pass: "C@rifio00"
// }
// });
dotenv.config();

// export async function sendEmail(to: string, from: string, subject: string, body: string) {
// const options = {
// from: from,
// to: to,
// subject: subject,
// text: body
// };
// transporter.sendMail(options, (error, info) => {
// if (error) {
// console.log(error);
// } else {
// console.log("Email sent: " + info.response);
// }
// });
// }
const transporter = nodemailer.createTransport({
service: process.env.EMAIL_SERVICE,
auth: {
user: process.env.EMAIL_USERNAME,
pass: process.env.EMAIL_PASSWORD,
},
});

export interface SendEmailOptions {
to: string;
subject: string;
text: string;
}

export async function sendEmail(options: SendEmailOptions) {
const sendOptions: SendMailOptions = {
...options,
from: process.env.EMAIL_FROM,
};
transporter.sendMail(sendOptions, (error, info) => {
if (error) {
console.log(error);
} else {
console.log("Email sent: " + info.response);
}
});
}

0 comments on commit 8cf24a1

Please sign in to comment.