Got emails working

master
Keith Irwin 2021-11-25 10:47:37 -07:00
parent 74635c17c8
commit e5bd16f67d
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
1 changed files with 8 additions and 8 deletions

View File

@ -3,23 +3,22 @@
require('dotenv').config()
const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const {verify} = require('hcaptcha')
console.log(`Connecting to ${process.env.MAIL_SERVER} as ${process.env.MAIL_USER} ${process.env.MAIL_PASS}`)
const mailer = require('nodemailer').createTransport({
host: process.env.MAIL_SERVER,
port: 587,
secure: false, // STARTTLS LATER
auth: {
user: process.env.MAIL_USER,
pass: process.env.MAIL_PASS,
},
tls: {
rejectUnauthorized: false,
},
})
//app.use(express.json())
app.use(bodyParser.json())
app.use(express.json())
app.post('/', async (req, res) => {
// Check token
@ -41,9 +40,10 @@ app.post('/', async (req, res) => {
// Send email
let mail_res;
try {
console.log(`Sending email from ${from}...`)
console.log(`Sending email from ${from} to ${process.env.MAIL_TO}...`)
mail_res = await mailer.sendMail({
from: from,
from: 'www.ki9.us/contact <contact@ki9.us>',
replyTo: from,
to: process.env.MAIL_TO,
subject: req.body['subj'],
text: req.body['msg'],