Skip to content

Commit

Permalink
Added nodeMailer.js code and transporter.js that is called within nod…
Browse files Browse the repository at this point in the history
…eMailer
  • Loading branch information
SubinQKim committed Dec 3, 2023
1 parent b23563e commit 4ec8369
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
28 changes: 27 additions & 1 deletion routes/nodeMailer.js
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
//setup
const express = require('express');
const transporter = require('../transporter');
// TODO: add verifyToken

const emailRouter = express();

emailRouter.use(express.json());

emailRouter.post('/send', (req, res) => {
const { email, messageHtml, subject } = req.body;
const mail = {
from: `${process.env.REACT_APP_EMAIL_FIRST_NAME} ${process.env.REACT_APP_EMAIL_LAST_NAME} ${process.env.REACT_APP_EMAIL_USERNAME}`,
to: email,
subject,
html: messageHtml,
};

transporter.sendMail(mail, (err) => {
if (err) {
res.status(500).send(`Transporter Error: ${err}`);
} else {
res.status(200).send('Transporter Backend Successfully Sent');
}
});
});

module.exports = emailRouter;
18 changes: 18 additions & 0 deletions transporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const nodemailer = require('nodemailer');

require('dotenv').config();

// sender information
const transport = {
host: 'smtp.gmail.com', // e.g. smtp.gmail.com
auth: {
user: process.env.REACT_APP_EMAIL_USERNAME,
pass: process.env.REACT_APP_EMAIL_PASSWORD,
},
from: process.env.REACT_APP_EMAIL_USERNAME,
secure: true,
};

const transporter = nodemailer.createTransport(transport);

module.exports = transporter;

0 comments on commit 4ec8369

Please sign in to comment.