Skip to content

Instantly share code, notes, and snippets.

@AbrahamSalloum
Last active February 12, 2022 22:37
Show Gist options
  • Save AbrahamSalloum/7ec79e1b79f59fb16cf5a84aebf4e973 to your computer and use it in GitHub Desktop.
Save AbrahamSalloum/7ec79e1b79f59fb16cf5a84aebf4e973 to your computer and use it in GitHub Desktop.
const express = require('express');
const app = express();
const helmet = require("helmet");
const nodemailer = require("nodemailer");
require('dotenv').config()
app.use(express.json())
app.use(helmet());
const transporter = nodemailer.createTransport({
host: process.env.SMTPHOST,
port: process.env.SMTPPORT,
auth: {
user: process.env.EMAILID,
pass: process.env.EMAILPW,
},
});
app.post('/mail/', async (req, res) => {
let emailreq;
try {
if(!!req.body){
emailreq = req.body
} else {
emailreq = {}
}
let emaildata = {
to: process.env.EMAILID,
from: process.env.EMAILID,
subject: !!emailreq.subject ? emailreq.subject : `No Subject ${Date.now()}`,
text: JSON.stringify(emailreq)
}
let info = await transporter.sendMail(emaildata);
res.send(`Hello at: ${Date.now()}`)
} catch {
res.status(500).send(`Sad at: ${Date.now()}`)
}
})
const port = process.env.APPPORT || 3003
app.listen(port, () => console.log(`Mailer listening on port ${port}..."`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment