Got emails working
parent
74635c17c8
commit
e5bd16f67d
16
index.js
16
index.js
|
@ -3,23 +3,22 @@
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const app = express()
|
const app = express()
|
||||||
const bodyParser = require('body-parser')
|
|
||||||
const {verify} = require('hcaptcha')
|
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({
|
const mailer = require('nodemailer').createTransport({
|
||||||
host: process.env.MAIL_SERVER,
|
host: process.env.MAIL_SERVER,
|
||||||
port: 587,
|
port: 587,
|
||||||
secure: false, // STARTTLS LATER
|
|
||||||
auth: {
|
auth: {
|
||||||
user: process.env.MAIL_USER,
|
user: process.env.MAIL_USER,
|
||||||
pass: process.env.MAIL_PASS,
|
pass: process.env.MAIL_PASS,
|
||||||
},
|
},
|
||||||
|
tls: {
|
||||||
|
rejectUnauthorized: false,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
//app.use(express.json())
|
app.use(express.json())
|
||||||
|
|
||||||
app.use(bodyParser.json())
|
|
||||||
|
|
||||||
app.post('/', async (req, res) => {
|
app.post('/', async (req, res) => {
|
||||||
|
|
||||||
// Check token
|
// Check token
|
||||||
|
@ -41,9 +40,10 @@ app.post('/', async (req, res) => {
|
||||||
// Send email
|
// Send email
|
||||||
let mail_res;
|
let mail_res;
|
||||||
try {
|
try {
|
||||||
console.log(`Sending email from ${from}...`)
|
console.log(`Sending email from ${from} to ${process.env.MAIL_TO}...`)
|
||||||
mail_res = await mailer.sendMail({
|
mail_res = await mailer.sendMail({
|
||||||
from: from,
|
from: 'www.ki9.us/contact <contact@ki9.us>',
|
||||||
|
replyTo: from,
|
||||||
to: process.env.MAIL_TO,
|
to: process.env.MAIL_TO,
|
||||||
subject: req.body['subj'],
|
subject: req.body['subj'],
|
||||||
text: req.body['msg'],
|
text: req.body['msg'],
|
||||||
|
|
Loading…
Reference in New Issue