Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up the nodeMailer route and the transporter #28

Merged
merged 4 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions routes/nodeMailer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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;
ThatMegamind marked this conversation as resolved.
Show resolved Hide resolved
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');
ThatMegamind marked this conversation as resolved.
Show resolved Hide resolved

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;
ThatMegamind marked this conversation as resolved.
Show resolved Hide resolved
Loading