Kene-s-Cribs-Website/src/homePage/index.js
2021-04-01 21:09:49 -04:00

59 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var express = require('express');
var router = express.Router();
var nodemailer = require('nodemailer');
var cors = require('cors');
const creds = require('./config');
var transport = {
host: 'smtp.mailtrap.io', // Dont forget to replace with the SMTP host of your provider
port: 2525,
auth: {
user: creds.USER,
pass: creds.PASS
}
}
var transporter = nodemailer.createTransport(transport)
transporter.verify((error, success) => {
if (error) {
console.log(error);
} else {
console.log('Server is ready to take messages');
}
});
router.post('/send', (req, res, next) => {
var firstname = req.body.firstname
var lastname = req.body.lastname
var email = req.body.email
var message = req.body.message
var content = `firstname: ${firstname} \n lastname: ${lastname} \n email: ${email} \n message: ${message} `
var mail = {
from: email,
to: 'kenes@cribs.com', // Change to email address that you want to receive messages on
subject: 'New Message from Contact Form',
text: content
}
transporter.sendMail(mail, (err, data) => {
if (err) {
res.json({
status: 'fail'
})
} else {
res.json({
status: 'success'
})
}
})
})
const app = express()
app.use(cors())
app.use(express.json())
app.use('/', router)
app.listen(3002)
export { default } from "./homePage";