generated from ctc-uci/npo-backend-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added nodeMailer.js code and transporter.js that is called within nod…
…eMailer
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |