Skip to content

Commit

Permalink
Mailer Somewhat Ready
Browse files Browse the repository at this point in the history
  • Loading branch information
jaison080 committed Dec 25, 2023
1 parent b288c18 commit 0a1dc48
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions functions/mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,44 @@ const transporter = nodemailer.createTransport({
});

const main = async (body) => {
try {
const mailOptions = {
from: "IEDC MEC Collab",
to: body.toEmail,
subject: body.subject,
html: body.content,
};
await transporter.sendMail(mailOptions);
return `Sent mail to ${body.toEmail} with subject ${body.subject}`;
} catch (error) {
return `Failed to send email to ${body.toEmail} having error : ${error}`;
if (body.password !== process.env.MAILER_PASSWORD || !body.password) {
return { status: 401, message: "Unauthorized" };
} else {
if (!body.toEmail) {
return {
status: 500,
message: `No Reciever Email Found.`,
};
} else if (!body.subject) {
return {
status: 500,
message: `No Subject Found.`,
};
} else if (!body.content) {
return {
status: 500,
message: `No Content Found.`,
};
} else {
try {
const mailOptions = {
from: "IEDC MEC Collab",
to: body.toEmail,
subject: body.subject,
html: body.content,
};
await transporter.sendMail(mailOptions);
return {
status: 200,
message: `Sent mail to ${body.toEmail} with subject ${body.subject}`,
};
} catch (error) {
return {
status: 500,
message: `Failed to send email to ${body.toEmail} having error : ${error}`,
};
}
}
}
};

Expand Down

0 comments on commit 0a1dc48

Please sign in to comment.