Long story short, I wanted to add a email system to my application so I decided on Nodemailer. Everything works fine on localhost but once I try to send an email from my heroku deployed site, it fails with a 500
internal error.
I've already done the stuff with my gmail account to allow it to accept unsecure apps and stuff.
Here is my nodemailer setup:
app.post('/sendMail', (req, res) => {
const { name, email, total } = req.body
const nameCheck = name
.split(' ')
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ')
const output = `
<p>Thanks for shopping with us, ${nameCheck}.</p>
<p>Your Total is $${total}</p>
<hr />
<p>Gabriel Pozo - React Cart Developer / Owner</p>
<a href="https://reactshoppingcart1.herokuapp.com/">Shop</a>
`
const transporter = nodemailer.createTransport({
service: 'gmail',
port: 25,
secure: false,
auth: {
user: 'beyondutraining@gmail.com',
pass
},
tls: { rejectUnauthorized: false }
})
const mailOptions = {
from: '"Gabriel" <beyondutraining@gmail.com>',
to: email,
subject: 'Your Order',
html: output
}
transporter.sendMail(mailOptions, (error, info) => {
error ? res.sendStatus(500) : res.sendStatus(200)
})
})
This is how I'm serving static files from React:
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'))
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
})
}
This is how I'm assigning env
variables:
module.exports = {
PASS: process.env.PASS
}
If there's any other code you'd like, let me know!